1 /*********************************************************************************************************//**
2  * @file    ht32f5xxxx_sled.c
3  * @version $Rev:: 3309         $
4  * @date    $Date:: 2018-12-12 #$
5  * @brief   This file provides all the SLED firmware functions.
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 /* Includes ------------------------------------------------------------------------------------------------*/
29 #include "ht32f5xxxx_sled.h"
30 
31 /** @addtogroup HT32F5xxxx_Peripheral_Driver HT32F5xxxx Peripheral Driver
32   * @{
33   */
34 
35 /** @defgroup SLED SLED
36   * @brief SLED driver modules
37   * @{
38   */
39 
40 
41 /* Global functions ----------------------------------------------------------------------------------------*/
42 /** @defgroup SLED_Exported_Functions SLED exported functions
43   * @{
44   */
45 /*********************************************************************************************************//**
46  * @brief Deinitialize the specified SLED peripheral registers to their default reset values.
47  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
48  * @retval None
49  ************************************************************************************************************/
SLED_DeInit(HT_SLED_TypeDef * SLEDx)50 void SLED_DeInit(HT_SLED_TypeDef* SLEDx)
51 {
52   RSTCU_PeripReset_TypeDef RSTCUReset = {{0}};
53 
54   /* Check the parameters                                                                                   */
55   Assert_Param(IS_SLED(SLEDx));
56 
57   if (SLEDx == HT_SLED0)
58   {
59     RSTCUReset.Bit.SLED0 = 1;
60   }
61   #if(LIBCFG_SLED1)
62   else if (SLEDx == HT_SLED1)
63   {
64     RSTCUReset.Bit.SLED1 = 1;
65   }
66   #endif
67 
68   RSTCU_PeripReset(RSTCUReset, ENABLE);
69 }
70 
71 /*********************************************************************************************************//**
72  * @brief Initialize the specified SLED peripheral according to the specified parameters in the SLED_InitStruct.
73  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
74  * @param SLED_InitStruct: pointer to a SLED_InitTypeDef structure.
75  * @retval None
76  ************************************************************************************************************/
SLED_Init(HT_SLED_TypeDef * SLEDx,SLED_InitTypeDef * SLED_InitStruct)77 void SLED_Init(HT_SLED_TypeDef* SLEDx, SLED_InitTypeDef* SLED_InitStruct)
78 {
79   /* Check the parameters                                                                                   */
80   Assert_Param(IS_SLED(SLEDx));
81 
82   SLEDx->CDR = (SLED_InitStruct->BaudRate       <<  8)
83              | (SLED_InitStruct->ClockPrescaler <<  0);
84 
85   SLEDx->TCR = (SLED_InitStruct->TRST           << 16)
86              | (SLED_InitStruct->T1H            <<  8)
87              | (SLED_InitStruct->T0H            <<  0);
88 
89   SLEDx->CR = (SLED_InitStruct->SyncState       << 10)
90             | (SLED_InitStruct->IdleState       <<  9)
91             | (SLED_InitStruct->ResetState      <<  8)
92             | (SLED_InitStruct->SyncMode        <<  3)
93             | (SLED_InitStruct->OutputPolarity  <<  2);
94 }
95 
96 /*********************************************************************************************************//**
97  * @brief Enable or Disable the specified SLED peripheral.
98  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
99  * @param NewState: This parameter can be ENABLE or DISABLE.
100  * @retval None
101  ************************************************************************************************************/
SLED_Cmd(HT_SLED_TypeDef * SLEDx,ControlStatus NewState)102 void SLED_Cmd(HT_SLED_TypeDef* SLEDx, ControlStatus NewState)
103 {
104   /* Check the parameters                                                                                   */
105   Assert_Param(IS_SLED(SLEDx));
106   Assert_Param(IS_CONTROL_STATUS(NewState));
107 
108   if (NewState != DISABLE)
109   {
110     SLEDx->CR |= (1 << 0);
111   }
112   else
113   {
114     SLEDx->CR &= ~(1 << 0);
115   }
116 }
117 
118 /*********************************************************************************************************//**
119  * @brief Enable or Disable the specified SLED output.
120  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
121  * @param NewState: This parameter can be ENABLE or DISABLE.
122  * @retval None
123  ************************************************************************************************************/
SLED_OutputCmd(HT_SLED_TypeDef * SLEDx,ControlStatus NewState)124 void SLED_OutputCmd(HT_SLED_TypeDef* SLEDx, ControlStatus NewState)
125 {
126   /* Check the parameters                                                                                   */
127   Assert_Param(IS_SLED(SLEDx));
128   Assert_Param(IS_CONTROL_STATUS(NewState));
129 
130   if (NewState != DISABLE)
131   {
132     SLEDx->CR |= (1 << 1);
133   }
134   else
135   {
136     SLEDx->CR &= ~(1 << 1);
137   }
138 }
139 
140 /*********************************************************************************************************//**
141  * @brief Enable or Disable the specified SLED PDMA request.
142  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
143  * @param NewState: This parameter can be ENABLE or DISABLE.
144  * @retval None
145  ************************************************************************************************************/
SLED_PDMACmd(HT_SLED_TypeDef * SLEDx,ControlStatus NewState)146 void SLED_PDMACmd(HT_SLED_TypeDef* SLEDx, ControlStatus NewState)
147 {
148   /* Check the parameters                                                                                   */
149   Assert_Param(IS_SLED(SLEDx));
150   Assert_Param(IS_CONTROL_STATUS(NewState));
151 
152   if (NewState != DISABLE)
153   {
154     SLEDx->CR |= (1 << 4);
155   }
156   else
157   {
158     SLEDx->CR &= ~(1 << 4);
159   }
160 }
161 
162 /*********************************************************************************************************//**
163  * @brief Enable or Disable the specified SLED interrupt.
164  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
165  * @param NewState: This parameter can be ENABLE or DISABLE.
166  * @retval None
167  ************************************************************************************************************/
SLED_IntCmd(HT_SLED_TypeDef * SLEDx,ControlStatus NewState)168 void SLED_IntCmd(HT_SLED_TypeDef* SLEDx, ControlStatus NewState)
169 {
170   /* Check the parameters                                                                                   */
171   Assert_Param(IS_SLED(SLEDx));
172   Assert_Param(IS_CONTROL_STATUS(NewState));
173 
174   if (NewState != DISABLE)
175   {
176     SLEDx->CR |= (1 << 5);
177   }
178   else
179   {
180     SLEDx->CR &= ~(1 << 5);
181   }
182 }
183 
184 /*********************************************************************************************************//**
185  * @brief Clear the specified SLED interrupt flag.
186  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
187  * @retval None
188  ************************************************************************************************************/
SLED_ClearIntFlag(HT_SLED_TypeDef * SLEDx)189 void SLED_ClearIntFlag(HT_SLED_TypeDef* SLEDx)
190 {
191   /* Check the parameters                                                                                   */
192   Assert_Param(IS_SLED(SLEDx));
193 
194   SLEDx->SR |= (1 << 5);
195 }
196 
197 /*********************************************************************************************************//**
198  * @brief Insert a Reset Code on the specified SLED.
199  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
200  * @retval None
201  ************************************************************************************************************/
SLED_InsertResetCode(HT_SLED_TypeDef * SLEDx)202 void SLED_InsertResetCode(HT_SLED_TypeDef* SLEDx)
203 {
204   /* Check the parameters                                                                                   */
205   Assert_Param(IS_SLED(SLEDx));
206 
207   SLEDx->CR |= (1 << 15);
208 }
209 
210 /*********************************************************************************************************//**
211  * @brief Return the FIFO status of the specified SLED.
212  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
213  * @retval SET or RESET
214  ************************************************************************************************************/
SLED_GetResetCodeStatus(HT_SLED_TypeDef * SLEDx)215 FlagStatus SLED_GetResetCodeStatus(HT_SLED_TypeDef* SLEDx)
216 {
217   if ((SLEDx->CR & (1 << 15)) != RESET)
218     return SET;
219   else
220     return RESET;
221 }
222 
223 /*********************************************************************************************************//**
224  * @brief Return the BUSY status of the specified SLED.
225  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
226  * @retval SET or RESET
227  ************************************************************************************************************/
SLED_GetBusyStatus(HT_SLED_TypeDef * SLEDx)228 FlagStatus SLED_GetBusyStatus(HT_SLED_TypeDef* SLEDx)
229 {
230   if (SLEDx->SR & 1)
231     return SET;
232   else
233     return RESET;
234 }
235 
236 /*********************************************************************************************************//**
237  * @brief Set the specified SLED FIFO trigger level.
238  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
239  * @param FifoLevel: specify the FIFO trigger level.
240  *   This parameter can be one of the following values:
241  *     @arg SLED_FIFO_LEVEL_0 : data request will be inserted when FIFO data count is equal to 0
242  *     @arg SLED_FIFO_LEVEL_1 : data request will be inserted when FIFO data count is less than or equal to 1
243  *     @arg SLED_FIFO_LEVEL_2 : data request will be inserted when FIFO data count is less than or equal to 2
244  *     @arg SLED_FIFO_LEVEL_3 : data request will be inserted when FIFO data count is less than or equal to 3
245  * @retval None
246  ************************************************************************************************************/
SLED_FIFOTrigLevelConfig(HT_SLED_TypeDef * SLEDx,u8 FifoLevel)247 void SLED_FIFOTrigLevelConfig(HT_SLED_TypeDef* SLEDx, u8 FifoLevel)
248 {
249   /* Check the parameters                                                                                   */
250   Assert_Param(IS_SLED(SLEDx));
251   Assert_Param(IS_SLED_FIFO_LEVEL(FifoLevel));
252 
253   SLEDx->FCR = FifoLevel;
254 }
255 
256 /*********************************************************************************************************//**
257  * @brief Return the FIFO status of the specified SLED.
258  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
259  * @retval The number of data in FIFO.
260  ************************************************************************************************************/
SLED_GetFIFOStatus(HT_SLED_TypeDef * SLEDx)261 u8 SLED_GetFIFOStatus(HT_SLED_TypeDef* SLEDx)
262 {
263   return (SLEDx->FCR >> 24);
264 }
265 
266 /*********************************************************************************************************//**
267  * @brief Reset the specified SLED FIFO.
268  * @param SLEDx: where SLEDx is the selected SLED from the SLED peripherals.
269  * @retval None
270  ************************************************************************************************************/
SLED_FIFOReset(HT_SLED_TypeDef * SLEDx)271 void SLED_FIFOReset(HT_SLED_TypeDef* SLEDx)
272 {
273   /* Check the parameters                                                                                   */
274   Assert_Param(IS_SLED(SLEDx));
275 
276   SLEDx->FCR |= (1 << 0);
277 }
278 /**
279   * @}
280   */
281 
282 
283 /**
284   * @}
285   */
286 
287 /**
288   * @}
289   */
290