ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches

Full-featured 12-bit DAC_B driver. More...

#include <stdint.h>
#include "ra8_err.h"
Include dependency graph for ra8_dac_b.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ra8_dac_b_cfg_t
 Configuration descriptor for ra8_dac_b_init_configured. More...

Typedefs

typedef void(* ra8_dac_b_update_fn_t) (void *ctx, uint8_t channel)
 DAC update (conversion done) event callback.

Enumerations

enum  ra8_dac_b_vref_t : uint8_t {
  k_ra8_dac_b_vref_normal = 0U ,
  k_ra8_dac_b_vref_low = 1U
}
 VREFH operating-mode selection (DACR2.OFSSEL bit 8). More...
enum  ra8_dac_b_data_format_t : uint8_t {
  k_ra8_dac_b_format_right = 0U ,
  k_ra8_dac_b_format_left = 1U
}
 Data placement selection (DACR1.DPSEL bit 16). More...

Functions

ra8_err_t ra8_dac_b_init (void)
 Legacy init – zero every DAC_B register + enable MSTP.
ra8_err_t ra8_dac_b_init_configured (const ra8_dac_b_cfg_t *cfg)
 Initialise DAC_B with a full config descriptor.
ra8_err_t ra8_dac_b_deinit (void)
 Tear down the DAC_B peripheral.
ra8_err_t ra8_dac_b_write (uint8_t channel, uint16_t value)
 Programme a DAC channel with a 12-bit code.
ra8_err_t ra8_dac_b_set_vref (ra8_dac_b_vref_t vref)
 Change the DAC voltage reference at runtime.
ra8_err_t ra8_dac_b_set_output_enable (uint8_t channel, bool enable)
 Toggle output-enable for one channel at runtime.
ra8_err_t ra8_dac_b_get_status (uint8_t *out_mask)
 Read the DACR output-enable / DAE mask.
ra8_err_t ra8_dac_b_clear_status (void)
 Clear DAE + DAOE bits (disable DAC outputs).
ra8_err_t ra8_dac_b_attach_handler (ra8_dac_b_update_fn_t fn, void *ctx)
 Attach a DAC-update callback.
ra8_err_t ra8_dac_b_enter_stop (void)
 Put DAC_B into MSTP-gated stop.
ra8_err_t ra8_dac_b_exit_stop (void)
 Exit MSTP-gated stop.
void ra8_dac_b_dispatch_update (uint8_t channel)
 Dispatch a DAC-update event – fire the registered callback.

Detailed Description

Full-featured 12-bit DAC_B driver.

Tag
[Ring 3 / HAL] {World: NS}

full build-out of the RA8D2 DAC_B peripheral. Extends the write stub with: descriptor-based init, deinit, runtime reference reconfigure, output-enable controls, interrupt-mode attach / dispatch, power transition.

Definition in file ra8_dac_b.h.

Typedef Documentation

◆ ra8_dac_b_update_fn_t

typedef void(* ra8_dac_b_update_fn_t) (void *ctx, uint8_t channel)

DAC update (conversion done) event callback.

Parameters
[in]ctxCaller context.
[in]channelChannel that finished updating.

Definition at line 82 of file ra8_dac_b.h.

Enumeration Type Documentation

◆ ra8_dac_b_data_format_t

enum ra8_dac_b_data_format_t : uint8_t

Data placement selection (DACR1.DPSEL bit 16).

Mirrors the FSP dac_data_format_t semantics for DAC_B: 0 selects right-justified 12-bit data in the 16-bit DADR; 1 selects left-justified 12-bit data.

Enumerator
k_ra8_dac_b_format_right 

DPSEL=0: right-justified (default).

k_ra8_dac_b_format_left 

DPSEL=1: left-justified.

Definition at line 53 of file ra8_dac_b.h.

◆ ra8_dac_b_vref_t

enum ra8_dac_b_vref_t : uint8_t

VREFH operating-mode selection (DACR2.OFSSEL bit 8).

Mirrors FSP dac_b_vrefh_t: only two values are supported by the RA8D2 DAC_B IP. NORMAL is used when VREFH >= 2.7 V; LOW is used when VREFH < 2.7 V. The driver writes this value left-shifted to DACR2 bit 8 (OFSSEL).

Enumerator
k_ra8_dac_b_vref_normal 

OFSSEL=0: VREFH >= 2.7V (default).

k_ra8_dac_b_vref_low 

OFSSEL=1: VREFH < 2.7V.

Definition at line 39 of file ra8_dac_b.h.

Function Documentation

◆ ra8_dac_b_attach_handler()

ra8_err_t ra8_dac_b_attach_handler ( ra8_dac_b_update_fn_t fn,
void * ctx )
nodiscard

Attach a DAC-update callback.

Parameters
[in]fnCallback fired on ISR dispatch.
[in]ctxContext forwarded to the callback.
Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 337 of file ra8_dac_b.c.

References k_ra8_ok, and s_dac_b_state.

◆ ra8_dac_b_clear_status()

ra8_err_t ra8_dac_b_clear_status ( void )
nodiscard

Clear DAE + DAOE bits (disable DAC outputs).

Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 330 of file ra8_dac_b.c.

References internal_stop_channel(), k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, and k_ra8_ok.

◆ ra8_dac_b_deinit()

ra8_err_t ra8_dac_b_deinit ( void )
nodiscard

Tear down the DAC_B peripheral.

Returns
ra8_err_t error code.
Postcondition
DACR == 0, MSTP released.
Since
0.1.0

Definition at line 260 of file ra8_dac_b.c.

References r_dac_b_regs_t::DACR0, r_dac_b_regs_t::DADR, k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, k_ra8_dacr0_mask_daoutdis, k_ra8_mstp_dac12_0, k_ra8_mstp_dac12_1, ra8_dac_b(), ra8_mstp_disable(), and s_dac_b_state.

◆ ra8_dac_b_dispatch_update()

void ra8_dac_b_dispatch_update ( uint8_t channel)

Dispatch a DAC-update event – fire the registered callback.

Parameters
[in]channelChannel that completed an update.
Since
0.1.0

See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.

Precondition
Driver state has been initialized by the matching *_init.
Caller has validated all pointer parameters.
Postcondition
Side effects are limited to those documented in the header.
No global state is modified on the error path.
Note
Thread safety: see the header declaration.

Definition at line 362 of file ra8_dac_b.c.

References k_ra8_dac_b_channel_count, and s_dac_b_state.

◆ ra8_dac_b_enter_stop()

ra8_err_t ra8_dac_b_enter_stop ( void )
nodiscard

Put DAC_B into MSTP-gated stop.

Since
0.1.0

Definition at line 344 of file ra8_dac_b.c.

References internal_disable_channel(), k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, k_ra8_mstp_dac12_0, k_ra8_mstp_dac12_1, and ra8_mstp_disable().

◆ ra8_dac_b_exit_stop()

ra8_err_t ra8_dac_b_exit_stop ( void )
nodiscard

Exit MSTP-gated stop.

Since
0.1.0

Definition at line 352 of file ra8_dac_b.c.

References k_ra8_mstp_dac12_0, k_ra8_mstp_dac12_1, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, and s_tag.

◆ ra8_dac_b_get_status()

ra8_err_t ra8_dac_b_get_status ( uint8_t * out_mask)
nodiscard

Read the DACR output-enable / DAE mask.

Parameters
[out]out_maskDACR value masked to the control bits.
Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 310 of file ra8_dac_b.c.

References r_dac_b_regs_t::DACR0, k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, k_ra8_dacr0_mask_dacen, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_dac_b(), and s_tag.

◆ ra8_dac_b_init()

ra8_err_t ra8_dac_b_init ( void )
nodiscard

Legacy init – zero every DAC_B register + enable MSTP.

Returns
k_ra8_ok on success.
Since
0.1.0

Definition at line 153 of file ra8_dac_b.c.

References internal_disable_channel(), k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, k_ra8_mstp_dac12_0, k_ra8_mstp_dac12_1, k_ra8_ok, ra8_log_info, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, and s_tag.

Referenced by ra8_nsc_dac_b_init().

◆ ra8_dac_b_init_configured()

ra8_err_t ra8_dac_b_init_configured ( const ra8_dac_b_cfg_t * cfg)
nodiscard

Initialise DAC_B with a full config descriptor.

Parameters
[in]cfgNon-NULL configuration descriptor.
Returns
ra8_err_t error code.
Precondition
IRQs masked or single-threaded init context.
ra8_mstp_init has been called.
Postcondition
On success DACR matches cfg and the DAC_B module is powered on via MSTP.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 234 of file ra8_dac_b.c.

References ra8_dac_b_cfg_t::enable_channel0, ra8_dac_b_cfg_t::enable_channel1, internal_apply_cfg(), internal_start_channel(), k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, k_ra8_mstp_dac12_0, k_ra8_mstp_dac12_1, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_info, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, and s_tag.

Referenced by internal_dac_b_demo_arm(), and internal_dac_demo_setup_or_halt().

◆ ra8_dac_b_set_output_enable()

ra8_err_t ra8_dac_b_set_output_enable ( uint8_t channel,
bool enable )
nodiscard

Toggle output-enable for one channel at runtime.

Parameters
[in]channel0 or 1.
[in]enableTrue -> drive the pin; false -> Hi-Z.
Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 293 of file ra8_dac_b.c.

References r_dac_b_regs_t::DACR0, k_ra8_dacr0_mask_dacen, k_ra8_err_invalid_arg, k_ra8_ok, and ra8_dac_b().

Referenced by main().

◆ ra8_dac_b_set_vref()

ra8_err_t ra8_dac_b_set_vref ( ra8_dac_b_vref_t vref)
nodiscard

Change the DAC voltage reference at runtime.

Parameters
[in]vrefNew reference source.
Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 281 of file ra8_dac_b.c.

References r_dac_b_regs_t::DACR2, k_ra8_dac_b_channel_0, k_ra8_dac_b_channel_1, k_ra8_dacr2_bit_ofssel, k_ra8_dacr2_mask_ofssel, k_ra8_ok, and ra8_dac_b().

◆ ra8_dac_b_write()

ra8_err_t ra8_dac_b_write ( uint8_t channel,
uint16_t value )
nodiscard

Programme a DAC channel with a 12-bit code.

Parameters
[in]channel0 or 1.
[in]valueRaw 12-bit code (clamped to 0..4095).
Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 172 of file ra8_dac_b.c.

References r_dac_b_regs_t::DADR, internal_ra8_dac_b_clamp(), k_ra8_err_invalid_arg, k_ra8_ok, ra8_dac_b(), ra8_log_info_val, and s_tag.

Referenced by internal_dac_demo_one_triangle_period(), main(), and ra8_nsc_dac_b_write().