1 /*!
2  * @file        tsc_filter.c
3  *
4  * @brief       This file contains all functions to manage the signal or delta filters.
5  *
6  * @version     V1.0.1
7  *
8  * @date        2022-09-20
9  *
10  * @attention
11  *
12  *  Copyright (C) 2020-2022 Geehy Semiconductor
13  *
14  *  You may not use this file except in compliance with the
15  *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
16  *
17  *  The program is only for reference, which is distributed in the hope
18  *  that it will be useful and instructional for customers to develop
19  *  their software. Unless required by applicable law or agreed to in
20  *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
21  *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
23  *  and limitations under the License.
24  */
25 
26 /* Includes */
27 #include "tsc_filter.h"
28 
29 /** @addtogroup TSC_Driver_Library TSC Driver Library
30   @{
31 */
32 
33 /** @addtogroup TSC_Filter_Driver TSC Filter Driver
34   @{
35 */
36 
37 /** @defgroup TSC_Filter_Macros Macros
38   @{
39 */
40 
41 /**@} end of group TSC_Filter_Macros */
42 
43 /** @defgroup TSC_Filter_Enumerations Enumerations
44   @{
45 */
46 
47 /**@} end of group TSC_Filter_Enumerations */
48 
49 /** @defgroup TSC_Filter_Structures Structures
50   @{
51 */
52 
53 /**@} end of group TSC_Filter_Structures */
54 
55 /** @defgroup TSC_Filter_Variables Variables
56   @{
57 */
58 
59 /**@} end of group TSC_Filter_Variables */
60 
61 /** @defgroup TSC_Filter_Functions Functions
62   @{
63 */
64 
65 /*!
66  * @brief       Example of measure value filter
67  *
68  * @param       preMeasn: Previous measure value
69  *
70  * @param       curMeasn: Current measure value
71  *
72  * @retval      Filtered measure
73  */
TSC_Filt_MeasFilter(TSC_tMeas_T preMeasn,TSC_tMeas_T curMeasn)74 TSC_tMeas_T TSC_Filt_MeasFilter(TSC_tMeas_T preMeasn, TSC_tMeas_T curMeasn)
75 {
76     TSC_tMeas_T value;
77 
78     value = (TSC_tMeas_T)(curMeasn << ACQ_FILTER_RANGE);
79 
80     if (preMeasn)
81     {
82         if (value <= preMeasn)
83         {
84             value = preMeasn - ((ACQ_FILTER_COEFF * (preMeasn - value)) >> 8);
85         }
86         else
87         {
88             value = preMeasn + ((ACQ_FILTER_COEFF * (value - preMeasn)) >> 8);
89         }
90     }
91     return (value);
92 }
93 
94 /*!
95  * @brief       Example of delta value filter
96  *
97  * @param       delta: Delta value to modify
98  *
99  * @retval      Filtered delta
100  */
TSC_Filt_DeltaFilter(TSC_tDelta_T delta)101 TSC_tDelta_T TSC_Filt_DeltaFilter(TSC_tDelta_T delta)
102 {
103     return (delta);
104 }
105 
106 /**@} end of group TSC_Filter_Functions */
107 /**@} end of group TSC_Filter_Driver */
108 /**@} end of group TSC_Driver_Library */
109 
110