Skip to content

Commit 104bbd1

Browse files
khoa-nguyen-18KhiemNguyenT
authored andcommitted
hal: renesas: ra: Initial support for ACMPHS driver
Initial support for ACMPHS driver with r_acmphs in Renesas HAL Signed-off-by: Khoa Nguyen <[email protected]>
1 parent f01650d commit 104bbd1

File tree

5 files changed

+708
-0
lines changed

5 files changed

+708
-0
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_USB_HOST
7171
fsp/src/r_usb_host/r_usb_host.c)
7272
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_WDT
7373
fsp/src/r_wdt/r_wdt.c)
74+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_ACMPHS
75+
fsp/src/r_acmphs/r_acmphs.c)
7476

7577
if(CONFIG_USE_RA_FSP_SCE)
7678
zephyr_include_directories(
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/*
2+
* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef R_COMPARATOR_API_H
8+
#define R_COMPARATOR_API_H
9+
10+
/*******************************************************************************************************************//**
11+
* @defgroup COMPARATOR_API Comparator Interface
12+
* @ingroup RENESAS_ANALOG_INTERFACES
13+
* @brief Interface for comparators.
14+
*
15+
* @section COMPARATOR_API_SUMMARY Summary
16+
* The comparator interface provides standard comparator functionality, including generating an event when the
17+
* comparator result changes.
18+
*
19+
*
20+
* @{
21+
**********************************************************************************************************************/
22+
23+
/***********************************************************************************************************************
24+
* Includes
25+
**********************************************************************************************************************/
26+
27+
/** Includes board and MCU related header files. */
28+
#include "bsp_api.h"
29+
30+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
31+
FSP_HEADER
32+
33+
/**********************************************************************************************************************
34+
* Macro definitions
35+
**********************************************************************************************************************/
36+
37+
/*****************************************************************************
38+
* Typedef definitions
39+
******************************************************************************/
40+
41+
/** Comparator control block. Allocate an instance specific control block to pass into the comparator API calls.
42+
*/
43+
typedef void comparator_ctrl_t;
44+
45+
/** Select whether to invert the polarity of the comparator output. */
46+
typedef enum e_comparator_mode
47+
{
48+
COMPARATOR_MODE_NORMAL = 0, ///< Normal mode
49+
COMPARATOR_MODE_WINDOW = 1, ///< Window mode, not supported by all implementations
50+
} comparator_mode_t;
51+
52+
/** Trigger type: rising edge, falling edge, both edges, low level. */
53+
typedef enum e_comparator_trigger
54+
{
55+
COMPARATOR_TRIGGER_RISING = 1, ///< Rising edge trigger
56+
COMPARATOR_TRIGGER_FALLING = 2, ///< Falling edge trigger
57+
COMPARATOR_TRIGGER_BOTH_EDGE = 3, ///< Both edges trigger
58+
} comparator_trigger_t;
59+
60+
/** Select whether to invert the polarity of the comparator output. */
61+
typedef enum e_comparator_polarity_invert
62+
{
63+
COMPARATOR_POLARITY_INVERT_OFF = 0, ///< Do not invert polarity
64+
COMPARATOR_POLARITY_INVERT_ON = 1, ///< Invert polarity
65+
} comparator_polarity_invert_t;
66+
67+
/** Select whether to include the comparator output on the output pin. */
68+
typedef enum e_comparator_pin_output
69+
{
70+
COMPARATOR_PIN_OUTPUT_OFF = 0, ///< Do not include comparator output on output pin
71+
COMPARATOR_PIN_OUTPUT_ON = 1, ///< Include comparator output on output pin
72+
} comparator_pin_output_t;
73+
74+
/** Comparator digital filtering sample clock divisor settings. */
75+
typedef enum e_comparator_filter
76+
{
77+
COMPARATOR_FILTER_OFF = 0, ///< Disable debounce filter
78+
COMPARATOR_FILTER_1 = 4, ///< Filter using PCLK divided by 1, not supported by all implementations
79+
COMPARATOR_FILTER_8 = 1, ///< Filter using PCLK divided by 8
80+
COMPARATOR_FILTER_16 = 2, ///< Filter using PCLK divided by 16, not supported by all implementations
81+
COMPARATOR_FILTER_32 = 3, ///< Filter using PCLK divided by 32
82+
} comparator_filter_t;
83+
84+
/** Current comparator state. */
85+
typedef enum e_comparator_state
86+
{
87+
COMPARATOR_STATE_OUTPUT_LOW = 0, ///< VCMP < VREF if polarity is not inverted, VCMP > VREF if inverted
88+
COMPARATOR_STATE_OUTPUT_HIGH = 1, ///< VCMP > VREF if polarity is not inverted, VCMP < VREF if inverted
89+
COMPARATOR_STATE_OUTPUT_DISABLED = 2, ///< @ref comparator_api_t::outputEnable() has not been called
90+
} comparator_state_t;
91+
92+
/** Comparator information. */
93+
typedef struct st_comparator_info
94+
{
95+
uint32_t min_stabilization_wait_us; ///< Minimum stabilization wait time in microseconds
96+
} comparator_info_t;
97+
98+
/** Comparator status. */
99+
typedef struct st_comparator_status
100+
{
101+
comparator_state_t state; ///< Current comparator state
102+
} comparator_status_t;
103+
104+
/** Callback function parameter data */
105+
typedef struct st_comparator_callback_args
106+
{
107+
/** Placeholder for user data. Set in @ref comparator_api_t::open function in @ref comparator_cfg_t. */
108+
void const * p_context;
109+
uint32_t channel; ///< The physical hardware channel that caused the interrupt.
110+
} comparator_callback_args_t;
111+
112+
/** User configuration structure, used in open function */
113+
typedef struct st_comparator_cfg
114+
{
115+
uint8_t channel; ///< Hardware channel used.
116+
comparator_mode_t mode; ///< Normal or window mode
117+
comparator_trigger_t trigger; ///< Trigger setting.
118+
comparator_filter_t filter; ///< Digital filter clock divisor setting.
119+
comparator_polarity_invert_t invert; ///< Whether to invert output
120+
comparator_pin_output_t pin_output; ///< Whether to include output on output pin
121+
uint8_t vref_select; ///< Internal Vref Select
122+
uint8_t ipl; ///< Interrupt priority
123+
IRQn_Type irq; ///< NVIC interrupt number
124+
125+
/** Callback called when comparator event occurs. */
126+
void (* p_callback)(comparator_callback_args_t * p_args);
127+
128+
/** Placeholder for user data. Passed to the user callback in @ref comparator_callback_args_t. */
129+
void const * p_context;
130+
void const * p_extend; ///< Comparator hardware dependent configuration.
131+
} comparator_cfg_t;
132+
133+
/** Comparator functions implemented at the HAL layer will follow this API. */
134+
typedef struct st_comparator_api
135+
{
136+
/** Initialize the comparator.
137+
*
138+
* @param[in] p_ctrl Pointer to instance control block
139+
* @param[in] p_cfg Pointer to configuration
140+
*/
141+
fsp_err_t (* open)(comparator_ctrl_t * const p_ctrl, comparator_cfg_t const * const p_cfg);
142+
143+
/** Start the comparator.
144+
*
145+
* @param[in] p_ctrl Pointer to instance control block
146+
*/
147+
fsp_err_t (* outputEnable)(comparator_ctrl_t * const p_ctrl);
148+
149+
/** Provide information such as the recommended minimum stabilization wait time.
150+
*
151+
* @param[in] p_ctrl Pointer to instance control block
152+
* @param[out] p_info Comparator information stored here
153+
*/
154+
fsp_err_t (* infoGet)(comparator_ctrl_t * const p_ctrl, comparator_info_t * const p_info);
155+
156+
/** Provide current comparator status.
157+
*
158+
* @param[in] p_ctrl Pointer to instance control block
159+
* @param[out] p_status Status stored here
160+
*/
161+
fsp_err_t (* statusGet)(comparator_ctrl_t * const p_ctrl, comparator_status_t * const p_status);
162+
163+
/** Stop the comparator.
164+
*
165+
* @param[in] p_ctrl Pointer to instance control block
166+
*/
167+
fsp_err_t (* close)(comparator_ctrl_t * const p_ctrl);
168+
} comparator_api_t;
169+
170+
/** This structure encompasses everything that is needed to use an instance of this interface. */
171+
typedef struct st_comparator_instance
172+
{
173+
comparator_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
174+
comparator_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance
175+
comparator_api_t const * p_api; ///< Pointer to the API structure for this instance
176+
} comparator_instance_t;
177+
178+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
179+
FSP_FOOTER
180+
181+
/*******************************************************************************************************************//**
182+
* @} (end defgroup COMPARATOR_API)
183+
**********************************************************************************************************************/
184+
#endif
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef R_ACMPHS_H
8+
#define R_ACMPHS_H
9+
10+
/*******************************************************************************************************************//**
11+
* @addtogroup ACMPHS
12+
* @{
13+
**********************************************************************************************************************/
14+
15+
/***********************************************************************************************************************
16+
* Includes
17+
**********************************************************************************************************************/
18+
#include "bsp_api.h"
19+
#include "r_comparator_api.h"
20+
21+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
22+
FSP_HEADER
23+
24+
/***********************************************************************************************************************
25+
* Macro definitions
26+
**********************************************************************************************************************/
27+
28+
/***********************************************************************************************************************
29+
* Typedef definitions
30+
**********************************************************************************************************************/
31+
32+
typedef enum
33+
{
34+
ACMPHS_INPUT_NONE = 0,
35+
ACMPHS_INPUT_IVCMP0 = 1,
36+
ACMPHS_INPUT_IVCMP1 = 2,
37+
ACMPHS_INPUT_IVCMP2 = 4,
38+
ACMPHS_INPUT_IVCMP3 = 8,
39+
ACMPHS_INPUT_IVCMP4 = 16,
40+
ACMPHS_INPUT_IVCMP5 = 32,
41+
} acmphs_input_t;
42+
43+
typedef enum
44+
{
45+
ACMPHS_REFERENCE_NONE = 0,
46+
ACMPHS_REFERENCE_IVREF0 = 1,
47+
ACMPHS_REFERENCE_IVREF1 = 2,
48+
ACMPHS_REFERENCE_IVREF2 = 4,
49+
ACMPHS_REFERENCE_IVREF3 = 8,
50+
ACMPHS_REFERENCE_IVREF4 = 16,
51+
ACMPHS_REFERENCE_IVREF5 = 32,
52+
} acmphs_reference_t;
53+
54+
/* ACMPHS extended configuration */
55+
typedef struct
56+
{
57+
acmphs_input_t input_voltage;
58+
acmphs_reference_t reference_voltage;
59+
uint32_t maximum_status_retries; // Maximum number of status retries alowed
60+
} r_acmphs_extended_cfg_t;
61+
62+
/* Channel instance control block. DO NOT INITIALIZE. Initialization occurs in @ref comparator_api_t::open. */
63+
typedef struct st_acmphs_instance_ctrl
64+
{
65+
uint32_t open; // Used to determine if channel control block is in use
66+
const comparator_cfg_t * p_cfg; // Pointer to initial configurations
67+
R_ACMPHS0_Type * p_reg; // Pointer to register base address
68+
uint32_t maximum_status_retries; // Maximum number of status retries alowed
69+
} acmphs_instance_ctrl_t;
70+
71+
/***********************************************************************************************************************
72+
* Exported global variables
73+
**********************************************************************************************************************/
74+
75+
/* @cond INC_HEADER_DEFS_SEC */
76+
/* Filled in Interface API structure for this Instance. */
77+
extern const comparator_api_t g_comparator_on_acmphs;
78+
79+
/* @endcond */
80+
81+
/***********************************************************************************************************************
82+
* Public APIs
83+
**********************************************************************************************************************/
84+
fsp_err_t R_ACMPHS_Open(comparator_ctrl_t * p_ctrl, comparator_cfg_t const * const p_cfg);
85+
fsp_err_t R_ACMPHS_OutputEnable(comparator_ctrl_t * const p_ctrl);
86+
fsp_err_t R_ACMPHS_InfoGet(comparator_ctrl_t * const p_ctrl, comparator_info_t * const p_info);
87+
fsp_err_t R_ACMPHS_StatusGet(comparator_ctrl_t * const p_ctrl, comparator_status_t * const p_status);
88+
fsp_err_t R_ACMPHS_Close(comparator_ctrl_t * const p_ctrl);
89+
90+
/*******************************************************************************************************************//**
91+
* @} (end defgroup ACMPHS)
92+
**********************************************************************************************************************/
93+
94+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
95+
FSP_FOOTER
96+
97+
#endif // R_ACMPHS_H

0 commit comments

Comments
 (0)