/**
  ******************************************************************************
  * File Name          : RTC.h
  * Description        : This file provides code for the configuration
  *                      of the RTC instances.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under Ultimate Liberty license
  * SLA0044, the "License"; You may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
  *                             www.st.com/SLA0044
  *
  ******************************************************************************
  */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __rtc_H
#define __rtc_H
#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* USER CODE BEGIN Includes */
#include "time.h"
/* USER CODE END Includes */

extern RTC_HandleTypeDef hrtc;

/* USER CODE BEGIN Private defines */

//---------------------------------------------------------------


#define TIMER_IDX_CP			        0
#define TIMER_IDX_POWER			        1
#define TIMER_IDX_BLE 			        2
#define TIMER_IDX_SPEAKER		        3
#define TIMER_IDX_RTOS_STAT		        4
#define TIMER_IDX_RETRY_OC              5
#define TIMER_IDX_RETRY_LEAK            6
#define TIMER_IDX_RETRY_OT              7
#define TIMER_IDX_DEBUG                 8
#define TIMER_IDX_STATE_E               9
#define TIMER_IDX_LED_TEMP              10
#define TIMER_IDX_RFID_RELAY_OFF        11
#define TIMER_IDX_RELAY_1               12
#define TIMER_IDX_RELAY_2               13
#define TIMER_IDX_PE_DETECT             14
#define TIMER_IDX_WIFI                  15
#define TIMER_IDX_UPDATE                16
#define TIMER_IDX_SIMU_DISCONNECT       17

#ifdef FUNC_ADD_AC_DC_LEAK_TIMER
#define TIMER_IDX_RETRY_LEAK_AC         18
#define TIMER_IDX_RETRY_LEAK_DC         19
#endif

#define TIMER_COUNT			            20

//---------------------------------------------------------------

#define BLINKER_COUNT		            2
#define BLINKER_IDX_LED 	            0
#define BLINKER_IDX_SPEAKER	            1

#define FLICKER_COUNT		            2
#define FLICKER_IDX_BREATHE	            0
#define FLICKER_IDX_1		            1

#define BREATHE_LED_LOW_BOUNDARY            100   //Noode 200 , BYton and standard 100

//---------------------------------------------------------------

/* USER CODE END Private defines */

void MX_RTC_Init(void);

/* USER CODE BEGIN Prototypes */
extern void timerEnable(uint8_t tmrIdx, uint32_t timeoutSpec);
extern void timerDisable(uint8_t tmrIdx);
extern void timerRefresh(uint8_t tmrIdx);
extern void blinkerTimeSet(uint8_t idx, uint16_t on, uint16_t off, uint16_t rest, uint8_t count);
extern void flickerTimeSet(uint8_t idx, uint16_t on, uint16_t off);
extern void breatheTimeSet(uint16_t up, uint16_t down, uint16_t R_color, uint16_t G_color, uint16_t B_color, uint16_t W_color);
extern void disblinkerTime (uint8_t idx) ;
extern void LedOnRGBSet(uint16_t R_color, uint16_t G_color, uint16_t B_color, uint16_t W_color);
extern uint32_t timerGetTimePass(uint8_t tmrIdx) ;

extern RTC_DateTypeDef currentDate;
extern RTC_TimeTypeDef currentTime;
extern RTC_DateTypeDef setDate;
extern RTC_TimeTypeDef setTime;

extern struct TIMER
{
	uint64_t	timeoutSpec;	    // Timer timeout specification
	uint64_t	startTime;		    // Timetick in 1ms
    uint8_t		isEnable:1;			// Timer is enable flag
	uint8_t		isAlarm:1;			// Timer is alarm flag
}timer[TIMER_COUNT];

extern struct BLINK_TIMER
{
      uint16_t	blinkOnSpec;
      uint16_t	blinkOffSpec;
      uint16_t  blinkRestSpec;
      uint8_t   blinkCountSpec;
      uint32_t	blinkStartTime;
      uint32_t	resetStartTime;
      uint8_t   blinkCount;
      uint8_t	isOn:1;
      uint8_t	blinkisFinish:1;
}blinker[BLINKER_COUNT];

extern struct BREATHE_TIMER
{
    uint16_t	duty[4];
    uint16_t    RGB[4];
    uint8_t	isUp;
    uint16_t    timeUp;
    uint16_t    countUp;
    uint16_t    timeDown;
    uint16_t    countDown;
    uint16_t    countPause;
}breathe;

extern struct FLICKER_TIMER
{
	uint16_t	OnSpec;
	uint16_t	OffSpec;
        uint32_t	StartTime;
	uint8_t		isOn;
}flicker[FLICKER_COUNT];

/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif
#endif /*__ rtc_H */

/**
  * @}
  */

/**
  * @}
  */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
