G32R430 Device Driver Layer v1.0.4
G32R4xx Device Driver Layer API Reference
g32r4xx_ddl_comp.c
Go to the documentation of this file.
1
43#if defined(USE_FULL_DDL_DRIVER)
44
45/* Includes ------------------------------------------------------------------*/
46#include "g32r4xx_ddl_comp.h"
47#include "g32r4xx_ddl_rcm.h"
48
49#ifdef USE_FULL_ASSERT
50#include "g32_assert.h"
51#else
52#define ASSERT_PARAM(_PARAM_) ((void)0U)
53#endif /* USE_FULL_ASSERT */
54
58
59#if defined (COMP1) || defined (COMP2) || defined (COMP3) || defined (COMP4)
60
64
65/* Private types -------------------------------------------------------------*/
66/* Private variables ---------------------------------------------------------*/
67/* Private constants ---------------------------------------------------------*/
68/* Private macros ------------------------------------------------------------*/
69
73
74 /* Check of parameters for configuration of COMP hierarchical scope: */
75 /* COMP instance. */
76#define IS_DDL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
77 ( ((__COMP_INSTANCE__) < COMP4) ? \
78 ( ((__INPUT_PLUS__) == DDL_COMP_INPUT_PLUS_INP0) || \
79 ((__INPUT_PLUS__) == DDL_COMP_INPUT_PLUS_DAC1)) \
80 : \
81 ( ((__INPUT_PLUS__) == DDL_COMP_INPUT_PLUS_INP0) || \
82 ((__INPUT_PLUS__) == DDL_COMP_INPUT_PLUS_INP1) || \
83 ((__INPUT_PLUS__) == DDL_COMP_INPUT_PLUS_DAC1)) \
84)
85
86#define IS_DDL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
87( ((__COMP_INSTANCE__) < COMP4) ? \
88 ( ((__INPUT_MINUS__) == DDL_COMP_INPUT_MINUS_INN0) || \
89 ((__INPUT_MINUS__) == DDL_COMP_INPUT_MINUS_DAC1) ) \
90 : \
91 ( ((__INPUT_MINUS__) == DDL_COMP_INPUT_MINUS_INN0) || \
92 ((__INPUT_MINUS__) == DDL_COMP_INPUT_MINUS_INN1) || \
93 ((__INPUT_MINUS__) == DDL_COMP_INPUT_MINUS_DAC1) ) \
94)
95
96#define IS_DDL_COMP_OUTPUT_POLARITY(__POLARITY__) \
97 ( ((__POLARITY__) == DDL_COMP_OUTPUTPOL_NONINVERTED) || \
98 ((__POLARITY__) == DDL_COMP_OUTPUTPOL_INVERTED) \
99 )
100
101#define IS_DDL_COMP_OUTPUT_BLANK(__BLANK__) \
102 ( ((__BLANK__) == DDL_COMP_BLANK_0) || \
103 ((__BLANK__) == DDL_COMP_BLANK_1) || \
104 ((__BLANK__) == DDL_COMP_BLANK_2) || \
105 ((__BLANK__) == DDL_COMP_BLANK_3) || \
106 ((__BLANK__) == DDL_COMP_BLANK_4) || \
107 ((__BLANK__) == DDL_COMP_BLANK_6) || \
108 ((__BLANK__) == DDL_COMP_BLANK_7) \
109 )
110
114
115/* Private function prototypes -----------------------------------------------*/
116
117/* Exported functions --------------------------------------------------------*/
121
125
134ErrorStatus DDL_COMP_Init(COMP_TypeDef *COMPx, DDL_COMP_InitTypeDef *COMP_InitStruct)
135{
136 ErrorStatus status = SUCCESS;
137
138 /* Check parameters */
139 ASSERT_PARAM(IS_COMP_ALL_INSTANCE(COMPx));
140 ASSERT_PARAM(IS_DDL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus));
141 ASSERT_PARAM(IS_DDL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus));
144
145 /* COMP instance must not be locked */
146 if (DDL_COMP_IsLocked(COMPx) == 0UL)
147 {
148 /* Configuration of comparator instance */
149 MODIFY_REG(COMPx->CxCSR,
150 COMP_CSTS_VP_SEL |
151 COMP_CSTS_VN_SEL |
152 COMP_CSTS_BLANKSEL |
153 COMP_CSTS_POL,
154 COMP_InitStruct->InputPlus |
155 COMP_InitStruct->InputMinus |
156 COMP_InitStruct->OutputBlank |
157 COMP_InitStruct->OutputPol
158 );
159 }
160 else
161 {
162 status = ERROR;
163 }
164
165 return status;
166}
167
177ErrorStatus DDL_COMP_DeInit(COMP_TypeDef *COMPx)
178{
179 ErrorStatus status = SUCCESS;
180
181 /* Check parameters */
182 ASSERT_PARAM(IS_COMP_ALL_INSTANCE(COMPx));
183
184 /* COMP instance must not be locked */
185 if (DDL_COMP_IsLocked(COMPx) == 0UL)
186 {
187 /* De-initialize the COMP registers to the reset values */
188 DDL_COMP_WriteReg((COMPx), CxCSR, 0x00000000UL);
189 }
190 else
191 {
192 /* COMP instance is locked */
193 /* The only way to unlock the COMP instance is to perform a system reset */
194 status = ERROR;
195 }
196
197 return status;
198}
199
207{
208 /* Set COMP_InitStruct fields to default values */
209 COMP_InitStruct->InputPlus = DDL_COMP_INPUT_PLUS_INP0;
210 COMP_InitStruct->InputMinus = DDL_COMP_INPUT_MINUS_INN0;
211 COMP_InitStruct->OutputPol = DDL_COMP_OUTPUTPOL_NONINVERTED;
212 COMP_InitStruct->OutputBlank = DDL_COMP_BLANK_0;
213}
214
218
222
226
227#endif /* COMP1 || COMP2 */
228
232
233#endif /* USE_FULL_DDL_DRIVER */
G32 assert template file. This file should be copied to the application folder and renamed to g32_ass...
#define ASSERT_PARAM(_PARAM_)
Definition g32_assert.h:58
Header file of COMP DDL module.
Header file of RCM DDL module.
#define DDL_COMP_INPUT_MINUS_INN0
#define DDL_COMP_INPUT_PLUS_INP0
#define DDL_COMP_BLANK_0
#define DDL_COMP_OUTPUTPOL_NONINVERTED
ErrorStatus DDL_COMP_DeInit(COMP_TypeDef *COMPx)
De-Initialize COMP function.
ErrorStatus DDL_COMP_Init(COMP_TypeDef *COMPx, DDL_COMP_InitTypeDef *COMP_InitStruct)
Initialize COMP function.
void DDL_COMP_StructInit(DDL_COMP_InitTypeDef *COMP_InitStruct)
Set the fields of structure COMP_InitStruct to default values.
__STATIC_INLINE uint32_t DDL_COMP_IsLocked(COMP_TypeDef *COMPx)
Get comparator lock state.
#define DDL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__)
Write a value in COMP register.
#define IS_DDL_COMP_OUTPUT_POLARITY(__POLARITY__)
#define IS_DDL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__)
#define IS_DDL_COMP_OUTPUT_BLANK(__BLANK__)
#define IS_DDL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__)
COMP Init structure definition.