Skip to content

Commit b949591

Browse files
khoa-nguyen-18KhiemNguyenT
authored andcommitted
hal: renesas: ra: Initial support for DAC driver
Initial support for DAC driver with r_dac in Renesas HAL Signed-off-by: Khoa Nguyen <[email protected]>
1 parent c7c2af0 commit b949591

File tree

5 files changed

+663
-1
lines changed

5 files changed

+663
-1
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_DISPLAY
6464
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_MIPI_DSI
6565
fsp/src/r_mipi_dsi/r_mipi_dsi.c
6666
fsp/src/r_mipi_phy/r_mipi_phy.c)
67+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_DAC
68+
fsp/src/r_dac/r_dac.c)
6769

6870
if(CONFIG_USE_RA_FSP_SCE)
6971
zephyr_include_directories(
@@ -118,7 +120,7 @@ if(CONFIG_USE_RA_FSP_SCE)
118120
"fsp/src/r_sce/trng/*.c")
119121
zephyr_library_sources(${trng_srcs})
120122
endif()
121-
123+
122124
endif()
123125

124126
if(CONFIG_USE_RA_FSP_SDHI)

drivers/ra/fsp/inc/api/r_dac_api.h

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/*******************************************************************************************************************//**
8+
* @ingroup RENESAS_ANALOG_INTERFACES
9+
* @defgroup DAC_API DAC Interface
10+
* @brief Interface for D/A converters.
11+
*
12+
* @section DAC_API_SUMMARY Summary
13+
* The DAC interface provides standard Digital/Analog Converter functionality. A DAC application writes digital
14+
* sample data to the device and generates analog output on the DAC output pin.
15+
*
16+
*
17+
* @{
18+
**********************************************************************************************************************/
19+
20+
#ifndef R_DAC_API_H
21+
#define R_DAC_API_H
22+
23+
/***********************************************************************************************************************
24+
* Includes
25+
**********************************************************************************************************************/
26+
27+
/* Common error codes and definitions. */
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+
/** DAC Open API data format settings. */
42+
typedef enum e_dac_data_format
43+
{
44+
DAC_DATA_FORMAT_FLUSH_RIGHT = 0, ///< LSB of data is flush to the right leaving the top 4 bits unused.
45+
DAC_DATA_FORMAT_FLUSH_LEFT = 1 ///< MSB of data is flush to the left leaving the bottom 4 bits unused.
46+
} dac_data_format_t;
47+
48+
/** DAC information structure to store various information for a DAC */
49+
typedef struct dac_info
50+
{
51+
uint8_t bit_width; ///< Resolution of the DAC.
52+
} dac_info_t;
53+
54+
/** DAC Open API configuration parameter */
55+
typedef struct st_dac_cfg
56+
{
57+
uint8_t channel; ///< ID associated with this DAC channel
58+
bool ad_da_synchronized; ///< AD/DA synchronization
59+
void const * p_extend;
60+
} dac_cfg_t;
61+
62+
/** DAC control block. Allocate an instance specific control block to pass into the DAC API calls.
63+
*/
64+
typedef void dac_ctrl_t;
65+
66+
/** DAC driver structure. General DAC functions implemented at the HAL layer follow this API. */
67+
typedef struct st_dac_api
68+
{
69+
/** Initial configuration.
70+
*
71+
* @param[in] p_ctrl Pointer to control block. Must be declared by user. Elements set here.
72+
* @param[in] p_cfg Pointer to configuration structure. All elements of this structure must be set by user.
73+
*/
74+
fsp_err_t (* open)(dac_ctrl_t * const p_ctrl, dac_cfg_t const * const p_cfg);
75+
76+
/** Close the D/A Converter.
77+
*
78+
* @param[in] p_ctrl Control block set in @ref dac_api_t::open call for this timer.
79+
*/
80+
fsp_err_t (* close)(dac_ctrl_t * const p_ctrl);
81+
82+
/** Write sample value to the D/A Converter.
83+
*
84+
* @param[in] p_ctrl Control block set in @ref dac_api_t::open call for this timer.
85+
* @param[in] value Sample value to be written to the D/A Converter.
86+
*/
87+
fsp_err_t (* write)(dac_ctrl_t * const p_ctrl, uint16_t value);
88+
89+
/** Start the D/A Converter if it has not been started yet.
90+
*
91+
* @param[in] p_ctrl Control block set in @ref dac_api_t::open call for this timer.
92+
*/
93+
fsp_err_t (* start)(dac_ctrl_t * const p_ctrl);
94+
95+
/** Stop the D/A Converter if the converter is running.
96+
*
97+
* @param[in] p_ctrl Control block set in @ref dac_api_t::open call for this timer.
98+
*/
99+
fsp_err_t (* stop)(dac_ctrl_t * const p_ctrl);
100+
} dac_api_t;
101+
102+
/** This structure encompasses everything that is needed to use an instance of this interface. */
103+
typedef struct st_dac_instance
104+
{
105+
dac_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
106+
dac_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance
107+
dac_api_t const * p_api; ///< Pointer to the API structure for this instance
108+
} dac_instance_t;
109+
110+
/*******************************************************************************************************************//**
111+
* @} (end defgroup DAC_API)
112+
**********************************************************************************************************************/
113+
114+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
115+
FSP_FOOTER
116+
117+
#endif

drivers/ra/fsp/inc/instances/r_dac.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef R_DAC_H
8+
#define R_DAC_H
9+
10+
/***********************************************************************************************************************
11+
* Includes
12+
**********************************************************************************************************************/
13+
14+
#include "bsp_api.h"
15+
#include "r_dac_cfg.h"
16+
#include "r_dac_api.h"
17+
18+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
19+
FSP_HEADER
20+
21+
/*******************************************************************************************************************//**
22+
* @addtogroup DAC
23+
* @{
24+
**********************************************************************************************************************/
25+
26+
/***********************************************************************************************************************
27+
* Macro definitions
28+
**********************************************************************************************************************/
29+
30+
/***********************************************************************************************************************
31+
* Typedef definitions
32+
**********************************************************************************************************************/
33+
34+
/** DAC Reference voltage selection. */
35+
typedef enum e_dac_ref_volt_sel
36+
{
37+
DAC_VREF_NONE = 0x00, ///< No reference voltage selected
38+
DAC_VREF_AVCC0_AVSS0 = 0x01, ///< Select AVCC0/AVSS0
39+
DAC_VREF_IVREF_AVSS0 = 0x03, ///< Select Internal reference voltage/AVSS0
40+
DAC_VREF_VREFH_VREFL = 0x06 ///< Select VREFH/VREFL
41+
} dac_ref_volt_sel_t;
42+
43+
/** DAC instance control block. */
44+
typedef struct st_dac_instance_ctrl
45+
{
46+
uint8_t channel; // DAC channel number
47+
uint8_t channel_index; // Channel index to access bits
48+
uint32_t channel_opened; // DAC Driver ID
49+
bool output_amplifier_enabled; // DAC Output amplifier (on selected MCUs) enabled/disabled.
50+
bool internal_output_enabled; // Output provided to internal modules (on selected MCUs) enabled/disabled.
51+
R_DAC_Type * p_reg; // Base register for this channel
52+
} dac_instance_ctrl_t;
53+
54+
/** DAC extended configuration */
55+
typedef struct st_dac_extended_cfg
56+
{
57+
bool enable_charge_pump; ///< Enable DAC charge pump available on selected MCUs.
58+
bool output_amplifier_enabled; ///< Output amplifier enable available on selected MCUs.
59+
bool internal_output_enabled; ///< Internal output enable available on selected MCUs.
60+
dac_data_format_t data_format; ///< Data format
61+
dac_ref_volt_sel_t ref_volt_sel; ///< Reference voltage selection
62+
} dac_extended_cfg_t;
63+
64+
/**********************************************************************************************************************
65+
* Exported global variables
66+
**********************************************************************************************************************/
67+
68+
/** @cond INC_HEADER_DEFS_SEC */
69+
/** Filled in Interface API structure for this Instance. */
70+
extern const dac_api_t g_dac_on_dac;
71+
72+
/** @endcond */
73+
74+
/***********************************************************************************************************************
75+
* Public APIs
76+
**********************************************************************************************************************/
77+
fsp_err_t R_DAC_Open(dac_ctrl_t * p_api_ctrl, dac_cfg_t const * const p_cfg);
78+
fsp_err_t R_DAC_Write(dac_ctrl_t * p_api_ctrl, uint16_t value);
79+
fsp_err_t R_DAC_Start(dac_ctrl_t * p_api_ctrl);
80+
fsp_err_t R_DAC_Stop(dac_ctrl_t * p_api_ctrl);
81+
fsp_err_t R_DAC_Close(dac_ctrl_t * p_api_ctrl);
82+
83+
/*******************************************************************************************************************//**
84+
* @} (end defgroup DAC)
85+
**********************************************************************************************************************/
86+
87+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
88+
FSP_FOOTER
89+
90+
#endif // R_DAC_H

0 commit comments

Comments
 (0)