/**
  ******************************************************************************
  * @file    ys32md211_led.h
  * @author  YSPRING Application Team
  * @version V1.0.1
  * @date    2025.02.15
  * @brief   This file contains all the functions prototypes for the LED firmware 
  *          library.
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __YS32MD211_LED_H
#define __YS32MD211_LED_H

#ifdef __cplusplus
 extern "C" {
#endif

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

/** @addtogroup YS32MD211_StdPeriph_Driver
  * @{
  */

/** @addtogroup LED
  * @{
  */

/* Exported types ------------------------------------------------------------*/

/** 
  * @brief  LED Init structures definition  
  */
typedef struct{
    uint32_t LED_ClkDiv;    /*!< Specifies the LED division value to be configured.
                              This parameter can be any value of @ref LED_ClkDivision_define */ 

    uint32_t LED_OnTime0;     /*!< Specifies the LED On-time 0 value to be configured.
                              This parameter can be any value of @ref LED_OnTime0_1_define */

    uint32_t LED_OnTime1;     /*!< Specifies the LED On-time 1 value to be configured.
                              This parameter can be any value of @ref LED_OnTime0_1_define */

    uint32_t LED_ArrayMode;/*!< Specifies the array mode for the LED.
                              This parameter can be a value of @ref LED_ArrayMode_define */

    uint32_t LED_ScanFirst;/*!< Specifies the scan first line for the LED.
                              This parameter can be a value of @ref LED_ScanFirst_define*/

    uint32_t LED_ScanMode;/*!< Specifies the scan mode for the LED.
                              This parameter can be a value of @ref LED_ScanModeConfig_define*/
}LED_InitTypeDef;
  
/* Exported constants --------------------------------------------------------*/

/** @defgroup LED_ClkDivision_define
  * @{
  */ 
#define  IS_LED_CLK_DIV(CLK_DIV)                ((CLK_DIV) <= 0x0f)
/**
  * @}
  */ 

 /** @defgroup LED_OnTime0_1_define
  * @{
  */ 
#define  IS_LED_ON_TIME0_1(LED_T)                ((LED_T) <= 0xff)
                                          
/**
  * @}
  */ 
  
/** @defgroup LED_ScanFirst_define
  * @{
  */ 
#define  LED_ScanFirst_0      LED_GCR_SCAN_FIRST_LED0
#define  LED_ScanFirst_1      LED_GCR_SCAN_FIRST_LED1
#define  LED_ScanFirst_2      LED_GCR_SCAN_FIRST_LED2
#define  LED_ScanFirst_3      LED_GCR_SCAN_FIRST_LED3
#define  LED_ScanFirst_4      LED_GCR_SCAN_FIRST_LED4
#define  LED_ScanFirst_5      LED_GCR_SCAN_FIRST_LED5
#define  LED_ScanFirst_6      LED_GCR_SCAN_FIRST_LED6
#define  LED_ScanFirst_7      LED_GCR_SCAN_FIRST_LED7
#define  LED_ScanFirst_8      LED_GCR_SCAN_FIRST_LED8

#define  IS_LED_SCAN_FIRST(SCAN_FIRST)      (((SCAN_FIRST) == LED_ScanFirst_0)  || ((SCAN_FIRST) == LED_ScanFirst_1) || \
                                             ((SCAN_FIRST) == LED_ScanFirst_2)  || ((SCAN_FIRST) == LED_ScanFirst_3) || \
                                             ((SCAN_FIRST) == LED_ScanFirst_4)  || ((SCAN_FIRST) == LED_ScanFirst_5) || \
                                             ((SCAN_FIRST) == LED_ScanFirst_6)  || ((SCAN_FIRST) == LED_ScanFirst_7) || \
                                             ((SCAN_FIRST) == LED_ScanFirst_8))
                                          
/**
  * @}
  */ 


/** @defgroup LED_ArrayMode_define
  * @{
  */ 
#define  LED_ArrayMode_None   LED_GCR_ARRAY_MODE_None
#define  LED_ArrayMode_4X4    LED_GCR_ARRAY_MODE_44
#define  LED_ArrayMode_5X5    LED_GCR_ARRAY_MODE_55
#define  LED_ArrayMode_6X6    LED_GCR_ARRAY_MODE_66
#define  LED_ArrayMode_6X7    LED_GCR_ARRAY_MODE_67
#define  LED_ArrayMode_7X7    LED_GCR_ARRAY_MODE_77
#define  LED_ArrayMode_7X8    LED_GCR_ARRAY_MODE_78
#define  LED_ArrayMode_8X8    LED_GCR_ARRAY_MODE_88

#define  IS_LED_ARRAY_MODE(ARRAY_MODE)      (((ARRAY_MODE) == LED_ArrayMode_None) || ((ARRAY_MODE) == LED_ArrayMode_4X4) || \
                                             ((ARRAY_MODE) == LED_ArrayMode_5X5)  || ((ARRAY_MODE) == LED_ArrayMode_6X6) || \
                                             ((ARRAY_MODE) == LED_ArrayMode_6X7)  || ((ARRAY_MODE) == LED_ArrayMode_7X7) || \
                                             ((ARRAY_MODE) == LED_ArrayMode_7X8)  || ((ARRAY_MODE) == LED_ArrayMode_8X8))
                                          
/**
  * @}
  */ 
  
/** @defgroup LED_ScanModeConfig_define 
  * @{
  */ 
#define  LED_ScanMode_INT      0x00                 //Interrupt scan mode
#define  LED_ScanMode_LOOP     (LED_GCR_SCAN_MODE)  //Cycle scan mode

#define  IS_LED_SCAN_MODE(SCAN_MODE)      (((SCAN_MODE) == LED_ScanMode_INT)  || ((SCAN_MODE) == LED_ScanMode_LOOP))
                                          
/**
  * @}
  */ 

/** @defgroup LED_ITConfig 
  * @{
  */ 
#define  LED_IT_INT    LED_ICDR_INT

#define  IS_LED_IT_CONFIG(CONFIG)      ((CONFIG) == LED_IT_INT)
                                          
/**
  * @}
  */ 
  
/** @defgroup LED_BIT_ID
  * @{
  */ 
#define   LED_D0       0
#define   LED_D1       1
#define   LED_D2       2
#define   LED_D3       3
#define   LED_D4       4                                   
#define   LED_D5       5
#define   LED_D6       6
#define   LED_D7       7
#define   LED_D8       8
#define   LED_D9       9
#define   LED_D10      10
#define   LED_D11      11                                   
#define   LED_D12      12
#define   LED_D13      13
#define   LED_D14      14
#define   LED_D15      15
#define   LED_D16      16
#define   LED_D17      17
#define   LED_D18      18                                   
#define   LED_D19      19
#define   LED_D20      20
#define   LED_D21      21
#define   LED_D22      22
#define   LED_D23      23
#define   LED_D24      24
#define   LED_D25      25                                  
#define   LED_D26      26
#define   LED_D27      27
#define   LED_D28      28                                  
#define   LED_D29      29
#define   LED_D30      30
#define   LED_D31      31
#define   LED_D32      32
#define   LED_D33      33
#define   LED_D34      34
#define   LED_D35      35                                  
#define   LED_D36      36
#define   LED_D37      37
#define   LED_D38      38                                  
#define   LED_D39      39
#define   LED_D40      40
#define   LED_D41      41
#define   LED_D42      42
#define   LED_D43      43
#define   LED_D44      44
#define   LED_D45      45                                  
#define   LED_D46      46
#define   LED_D47      47
#define   LED_D48      48                                  
#define   LED_D49      49
#define   LED_D50      50
#define   LED_D51      51
#define   LED_D52      52
#define   LED_D53      53
#define   LED_D54      54
#define   LED_D55      55                                  
#define   LED_D56      56
#define   LED_D57      57
#define   LED_D58      58                                  
#define   LED_D59      59
#define   LED_D60      60
#define   LED_D61      61
#define   LED_D62      62
#define   LED_D63      63

#define  IS_LED_BIT_ID(LED_ID)                ((LED_ID) <= 63)
                                        
/**
  * @}
  */ 

/**
  * @}
  */
/** @defgroup LED_COMENR 
  * @{
  */
#define LED_HIGH_CURRENT_BIT0               0
#define LED_HIGH_CURRENT_BIT1               1
#define LED_HIGH_CURRENT_BIT2               2
#define LED_HIGH_CURRENT_BIT3               3
#define LED_HIGH_CURRENT_BIT4               4
#define LED_HIGH_CURRENT_BIT5               5
#define LED_HIGH_CURRENT_BIT6               6
#define LED_HIGH_CURRENT_BIT7               7
#define LED_HIGH_CURRENT_BIT8               8

#define IS_LED_HIGH_CURRENT(COMENX)  (((COMENX) == LED_HIGH_CURRENT_BIT0) || \
                                      ((COMENX) == LED_HIGH_CURRENT_BIT1) || \
                                      ((COMENX) == LED_HIGH_CURRENT_BIT2) || \
                                      ((COMENX) == LED_HIGH_CURRENT_BIT3) || \
                                      ((COMENX) == LED_HIGH_CURRENT_BIT4) || \
                                      ((COMENX) == LED_HIGH_CURRENT_BIT5) || \
                                      ((COMENX) == LED_HIGH_CURRENT_BIT6) || \
                                      ((COMENX) == LED_HIGH_CURRENT_BIT7) || \
                                      ((COMENX) == LED_HIGH_CURRENT_BIT8))
/**
  * @}
  */
/** @defgroup LED_IO_Mode
  * @{
  */
#define LED_NormalCurrent        ((uint16_t)0x0000)
#define LED_HighCurrent          ((uint16_t)0x0001)

#define IS_LED_MODE(Mode)            (((Mode) == LED_NormalCurrent) || \
                                      ((Mode) == LED_HighCurrent))
/**
  * @}
  */ 

/* Exported functions ------------------------------------------------------- */
/* Function used to set the LED configuration to the default reset state *****/
void LED_DeInit(void);

/* Initialization and Configuration functions *********************************/
void LED_Init(LED_InitTypeDef * LED_InitStruct);
void LED_StructInit(LED_InitTypeDef* LED_InitStruct);
void LED_Cmd(FunctionalState NewState);
void LED_ScanModeConfig(uint32_t ScanMode);
void LED_ArrayModeConfig(uint32_t ArrayMode);

/* LED ARRAY configuration functions **********************************************/
void LED_SetOnPeriodTime(uint32_t Bit0_31, uint32_t Bit32_63);
void LED_SetOnArray(uint32_t Bit0_31, uint32_t Bit32_63);
void LED_GetOnArray(uint32_t * pBit0_31, uint32_t * pBit32_63);

/* LED bit configuration functions **********************************************/
void LED_SetOnBit(uint8_t LED_ID, FunctionalState NewState);
FlagStatus LED_GetOnBit(uint8_t LED_ID);

/* Interrupts, flags management ***************************************/
ITStatus LED_GetITStatus(uint32_t LED_IT);
void LED_ClearITPendingBit(uint32_t LED_IT);

/* Current management functions ***************************************/
void LED_SetHighCurrent(uint16_t COMENx, uint16_t LED_Mode);
uint32_t LED_GetHighCurrent(void);

#ifdef __cplusplus
}
#endif

#endif /* __YS32MD211_LED_H */

/**
  * @}
  */

