1 /*********************************************************************************************************//**
2  * @file    ht32f5xxxx_ledc.h
3  * @version $Rev:: 6386         $
4  * @date    $Date:: 2022-10-27 #$
5  * @brief   The header file of the LED Controller library.
6  *************************************************************************************************************
7  * @attention
8  *
9  * Firmware Disclaimer Information
10  *
11  * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
12  *    code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
13  *    proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
14  *    other intellectual property laws.
15  *
16  * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
17  *    code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
18  *    other than HOLTEK and the customer.
19  *
20  * 3. The program technical documentation, including the code, is provided "as is" and for customer reference
21  *    only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
22  *    the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
23  *    the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
24  *
25  * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
26  ************************************************************************************************************/
27 
28 /* Define to prevent recursive inclusion -------------------------------------------------------------------*/
29 #ifndef __HT32F5XXXX_LEDC_H
30 #define __HT32F5XXXX_LEDC_H
31 
32 #ifdef __cplusplus
33  extern "C" {
34 #endif
35 
36 /* Includes ------------------------------------------------------------------------------------------------*/
37 #include "ht32.h"
38 
39 /** @addtogroup HT32F5xxxx_Peripheral_Driver HT32F5xxxx Peripheral Driver
40   * @{
41   */
42 
43 /** @addtogroup LEDC
44   * @{
45   */
46 
47 
48 /* Exported types ------------------------------------------------------------------------------------------*/
49 /** @defgroup LEDC_Exported_Types LEDC exported types
50   * @{
51   */
52 
53 /**
54  * @brief Selection of LEDC clock source
55  */
56 typedef enum
57 {
58   LEDC_SRC_PCLK = 0,
59   LEDC_SRC_LSI,                    /*!< Low speed internal clock, about 32KHz                               */
60   LEDC_SRC_LSE                     /*!< Low speed external 32768 Hz clock                                   */
61 } LEDC_SRC_Enum;
62 
63 /**
64  * @brief Selection of LEDC duty clock numbers
65  */
66 typedef enum
67 {
68   LEDC_DTYNUM_8 = 0,
69   LEDC_DTYNUM_16,
70   LEDC_DTYNUM_32,
71   LEDC_DTYNUM_64
72 } LEDC_DTYNUM_Enum;
73 
74 /**
75  * @brief Definition of LEDC Init Structure
76  */
77 typedef struct
78 {
79   LEDC_SRC_Enum    LEDC_ClockSource;
80   LEDC_DTYNUM_Enum LEDC_DutyClockNumber;
81   u32              LEDC_ClockPrescaler;
82   u32              LEDC_COMxEN;
83   u32              LEDC_DeadTime;
84 } LEDC_InitTypeDef;
85 
86 /**
87  * @brief Enumeration of LED layout mode.
88  */
89 typedef enum
90 {
91   COMMON_CATHODE,          /*!< LEDC SEG output polarity is non-inverted. */
92                            /*!< LEDC COM output polarity is non-inverted.*/
93   COMMON_CATHODE_WITH_NPN, /*!< LEDC SEG output polarity is non-inverted. */
94                            /*!< LEDC COM output polarity is inverted.*/
95   COMMON_ANODE_WITH_PNP,   /*!< LEDC SEG output polarity is inverted. */
96                            /*!< LEDC COM output polarity is non-inverted.*/
97   COMMON_ANODE_WITH_NPN,   /*!< LEDC SEG output polarity is inverted. */
98                            /*!< LEDC COM output polarity is inverted.*/
99 } LEDC_Mode;
100 
101 /**
102   * @}
103   */
104 
105 /* Exported constants --------------------------------------------------------------------------------------*/
106 /** @defgroup LEDC_Exported_Constants LEDC exported constants
107   * @{
108   */
109 
110 /* Definitions of LEDCER                                                                                    */
111 #define LEDC_COM0EN       0x0001   /*!< LEDC COM0 enable                                                    */
112 #define LEDC_COM1EN       0x0002   /*!< LEDC COM1 enable                                                    */
113 #define LEDC_COM2EN       0x0004   /*!< LEDC COM2 enable                                                    */
114 #define LEDC_COM3EN       0x0008   /*!< LEDC COM3 enable                                                    */
115 #define LEDC_COM4EN       0x0010   /*!< LEDC COM4 enable                                                    */
116 #define LEDC_COM5EN       0x0020   /*!< LEDC COM5 enable                                                    */
117 #define LEDC_COM6EN       0x0040   /*!< LEDC COM6 enable                                                    */
118 #define LEDC_COM7EN       0x0080   /*!< LEDC COM7 enable                                                    */
119 #if (LIBCFG_LEDC_NO_COM_8_11 == 0)
120 #define LEDC_COM8EN       0x0100   /*!< LEDC COM8 enable                                                    */
121 #define LEDC_COM9EN       0x0200   /*!< LEDC COM9 enable                                                    */
122 #define LEDC_COM10EN      0x0400   /*!< LEDC COM10 enable                                                   */
123 #define LEDC_COM11EN      0x0800   /*!< LEDC COM11 enable                                                   */
124 #endif
125 
126 /* Definitions of COMxPOL                                                                                   */
127 #define LEDC_COM0POL       0x00000001   /*!< LEDC COM0 polarity                                            */
128 #define LEDC_COM1POL       0x00000002   /*!< LEDC COM1 polarity                                            */
129 #define LEDC_COM2POL       0x00000004   /*!< LEDC COM2 polarity                                            */
130 #define LEDC_COM3POL       0x00000008   /*!< LEDC COM3 polarity                                            */
131 #define LEDC_COM4POL       0x00000010   /*!< LEDC COM4 polarity                                            */
132 #define LEDC_COM5POL       0x00000020   /*!< LEDC COM5 polarity                                            */
133 #define LEDC_COM6POL       0x00000040   /*!< LEDC COM6 polarity                                            */
134 #define LEDC_COM7POL       0x00000080   /*!< LEDC COM7 polarity                                            */
135 #if (LIBCFG_LEDC_NO_COM_8_11 == 0)
136 #define LEDC_COM8POL       0x00000100   /*!< LEDC COM8 polarity                                            */
137 #define LEDC_COM9POL       0x00000200   /*!< LEDC COM9 polarity                                            */
138 #define LEDC_COM10POL      0x00000400   /*!< LEDC COM10 polarity                                           */
139 #define LEDC_COM11POL      0x00000800   /*!< LEDC COM11 polarity                                           */
140 #endif
141 
142 /* Definitions of SEGxPOL                                                                                   */
143 #define LEDC_SEG0POL       0x00010000   /*!< LEDC SEG0 polarity                                            */
144 #define LEDC_SEG1POL       0x00020000   /*!< LEDC SEG1 polarity                                            */
145 #define LEDC_SEG2POL       0x00040000   /*!< LEDC SEG2 polarity                                            */
146 #define LEDC_SEG3POL       0x00080000   /*!< LEDC SEG3 polarity                                            */
147 #define LEDC_SEG4POL       0x00100000   /*!< LEDC SEG4 polarity                                            */
148 #define LEDC_SEG5POL       0x00200000   /*!< LEDC SEG5 polarity                                            */
149 #define LEDC_SEG6POL       0x00400000   /*!< LEDC SEG6 polarity                                            */
150 #define LEDC_SEG7POL       0x00800000   /*!< LEDC SEG7 polarity                                            */
151 
152 #define LEDC_FLAG_FRAME           (1UL << 0)
153 #define LEDC_INT_FRAME            (1UL << 0)
154 
155 
156 /* check parameter of the LEDC mode                                                                         */
157 #define IS_LEDC_MODE(x)      ((x == COMMON_CATHODE)        || (x == COMMON_CATHODE_WITH_NPN)  || \
158                               (x == COMMON_ANODE_WITH_PNP) || (x == COMMON_ANODE_WITH_NPN))
159 
160 /**
161  * @brief Used to check LEDC_SRC_Enum parameter
162  */
163 #define IS_LEDC_SRC(x)       ((x == LEDC_SRC_PCLK) || (x == LEDC_SRC_LSI) || (x == LEDC_SRC_LSE))
164 #define IS_LEDC_DTYNUM(x)    ((x == LEDC_DTYNUM_8) || (x == LEDC_DTYNUM_16) || (x == LEDC_DTYNUM_32) ||\
165                               (x == LEDC_DTYNUM_64))
166 #define IS_LEDC_PSC(x)        (x < 4096)
167 #define IS_LEDC_DTCR(x)       (x < 64)
168 #define IS_LEDC_COMEN(x)    (((x & 0xF000) == 0x0) && (x != 0x0))
169 #define IS_LEDC_COMPOL(x)   (((x & 0xFFFFF000) == 0x0) && (x != 0x0))
170 #define IS_LEDC_SEGPOL(x)   (((x & 0xFF00FFFF) == 0x0) && (x != 0x0))
171 
172 /**
173   * @}
174   */
175 
176 /* Exported functions --------------------------------------------------------------------------------------*/
177 /** @defgroup LEDC_Exported_Functions LEDC exported functions
178   * @{
179   */
180 void LEDC_DeInit(void);
181 void LEDC_Init(LEDC_InitTypeDef* LEDC_InitStruct);
182 void LEDC_ClockSourceConfig(LEDC_SRC_Enum Source);
183 void LEDC_Cmd(ControlStatus NewState);
184 void LEDC_IntConfig(ControlStatus NewState);
185 FlagStatus LEDC_GetFlagStatus(void);
186 void LEDC_ClearFlagStatus(void);
187 void LEDC_COMxConfig(u32 LEDC_COMxEN, ControlStatus Cmd);
188 void LEDC_SetDeadTimeDuty(u32 LEDC_DeadTimeDuty);
189 void LEDC_SetPolarityMode(u32 LEDC_COMxPOL, u32 LEDC_SEGxPOL , LEDC_Mode mode);
190 #define  LEDC_SetData(COMx, data)   HT_LEDC->DR[COMx] = data
191 #define  LEDC_GetData(COMx)         HT_LEDC->DR[COMx]
192 /**
193   * @}
194   */
195 
196 
197 /**
198   * @}
199   */
200 
201 /**
202   * @}
203   */
204 
205 #ifdef __cplusplus
206 }
207 #endif
208 
209 #endif
210