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

Full-featured High-Speed Analog Comparator (ACMPHS) driver. More...

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

Go to the source code of this file.

Data Structures

struct  ra8_acmphs_cfg_t
 Configuration descriptor for ra8_acmphs_channel_init. More...

Typedefs

typedef void(* ra8_acmphs_event_fn_t) (void *ctx, uint8_t channel)
 ACMPHS edge event callback.

Enumerations

enum  ra8_acmphs_edge_t : uint8_t {
  k_ra8_acmphs_edge_none = 0U ,
  k_ra8_acmphs_edge_rise = 1U ,
  k_ra8_acmphs_edge_fall = 2U ,
  k_ra8_acmphs_edge_both = 3U
}
 Edge detection mode (CMPCTL.CEG). More...

Functions

ra8_err_t ra8_acmphs_init (void)
 Legacy init – reset every channel to its power-on state.
ra8_err_t ra8_acmphs_channel_init (uint8_t channel, const ra8_acmphs_cfg_t *cfg)
 Initialise one channel with a full config descriptor.
ra8_err_t ra8_acmphs_channel_deinit (uint8_t channel)
 Tear down one channel (disable + clear CMPCTL).
ra8_err_t ra8_acmphs_channel_enable (uint8_t channel)
 Enable a single ACMPHS channel.
ra8_err_t ra8_acmphs_read_output (uint8_t channel, ra8_level_t *out)
 Read the live output of a channel.
ra8_err_t ra8_acmphs_set_inputs (uint8_t channel, uint8_t ivpsel, uint8_t ivrefsel)
 Change the input selection of one channel at runtime.
ra8_err_t ra8_acmphs_get_status (uint8_t channel, uint8_t *out_mask)
 Read CMPCTL enable / edge bits.
ra8_err_t ra8_acmphs_clear_status (uint8_t channel)
 Clear CMPCTL (disable + edge mode off) for one channel.
ra8_err_t ra8_acmphs_attach_handler (ra8_acmphs_event_fn_t fn, void *ctx)
 Attach an ACMPHS event callback (shared across all channels).
ra8_err_t ra8_acmphs_enter_stop (uint8_t channel)
 Put one channel into MSTP-gated stop.
ra8_err_t ra8_acmphs_exit_stop (uint8_t channel)
 Exit MSTP-gated stop for one channel.
void ra8_acmphs_dispatch (uint8_t channel)
 Dispatch an ACMPHS edge event – fire the registered callback.

Detailed Description

Full-featured High-Speed Analog Comparator (ACMPHS) driver.

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

full build-out of the RA8D2 ACMPHS block. Extends the enable/read stub with: per-channel descriptor init, deinit, runtime input selection, edge-sensitive IRQ attach / dispatch, filter config, power transition.

Definition in file ra8_acmphs.h.

Typedef Documentation

◆ ra8_acmphs_event_fn_t

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

ACMPHS edge event callback.

Parameters
[in]ctxCaller context.
[in]channelChannel that fired the edge.

Definition at line 65 of file ra8_acmphs.h.

Enumeration Type Documentation

◆ ra8_acmphs_edge_t

enum ra8_acmphs_edge_t : uint8_t

Edge detection mode (CMPCTL.CEG).

Enumerator
k_ra8_acmphs_edge_none 

Polling only, no edge trigger.

k_ra8_acmphs_edge_rise 

Rising edge.

k_ra8_acmphs_edge_fall 

Falling edge.

k_ra8_acmphs_edge_both 

Either edge.

Definition at line 35 of file ra8_acmphs.h.

Function Documentation

◆ ra8_acmphs_attach_handler()

ra8_err_t ra8_acmphs_attach_handler ( ra8_acmphs_event_fn_t fn,
void * ctx )
nodiscard

Attach an ACMPHS event callback (shared across all channels).

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 255 of file ra8_acmphs.c.

References k_ra8_ok, s_acmphs_ctx, and s_acmphs_fn.

◆ ra8_acmphs_channel_deinit()

ra8_err_t ra8_acmphs_channel_deinit ( uint8_t channel)
nodiscard

◆ ra8_acmphs_channel_enable()

ra8_err_t ra8_acmphs_channel_enable ( uint8_t channel)
nodiscard

Enable a single ACMPHS channel.

Parameters
[in]channelChannel index (0..5).
Returns
k_ra8_ok on success, k_ra8_err_invalid_arg if channel >= 6.
Since
0.1.0

Definition at line 113 of file ra8_acmphs.c.

References r_acmphs_regs_t::CMPCTL, k_ra8_acmphs_channel_count, k_ra8_acmphs_mask_hcen, k_ra8_err_invalid_arg, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, ra8_log_info_val, and s_tag.

◆ ra8_acmphs_channel_init()

ra8_err_t ra8_acmphs_channel_init ( uint8_t channel,
const ra8_acmphs_cfg_t * cfg )
nodiscard

Initialise one channel with a full config descriptor.

Parameters
[in]channelChannel 0..5.
[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
CMPCTL / CMPSEL0 / CMPSEL1 / CMPFIR reflect cfg.
Note
Thread safety: not thread-safe.
Since
0.1.0

Definition at line 166 of file ra8_acmphs.c.

References r_acmphs_regs_t::CMPCTL, r_acmphs_regs_t::CMPSEL0, r_acmphs_regs_t::CMPSEL1, ra8_acmphs_cfg_t::edge, ra8_acmphs_cfg_t::filter_en, ra8_acmphs_cfg_t::invert_out, ra8_acmphs_cfg_t::ivpsel, ra8_acmphs_cfg_t::ivrefsel, k_ra8_acmphs_cdfs_enabled_value, k_ra8_acmphs_cdfs_shift, k_ra8_acmphs_ceg_shift, k_ra8_acmphs_channel_count, k_ra8_acmphs_mask_cinv, k_ra8_acmphs_mask_hcen, k_ra8_acmphs_mstp_id_count, k_ra8_err_invalid_arg, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, s_acmphs_mstp_table, and s_tag.

Referenced by internal_acmphs_demo_setup().

◆ ra8_acmphs_clear_status()

ra8_err_t ra8_acmphs_clear_status ( uint8_t channel)
nodiscard

Clear CMPCTL (disable + edge mode off) for one channel.

Since
0.1.0

Definition at line 243 of file ra8_acmphs.c.

References r_acmphs_regs_t::CMPCTL, k_ra8_acmphs_channel_count, k_ra8_err_invalid_arg, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, and s_tag.

◆ ra8_acmphs_dispatch()

void ra8_acmphs_dispatch ( uint8_t channel)

Dispatch an ACMPHS edge event – fire the registered callback.

Parameters
[in]channelChannel 0..5 that fired the edge.
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 285 of file ra8_acmphs.c.

References k_ra8_acmphs_channel_count, s_acmphs_ctx, and s_acmphs_fn.

◆ ra8_acmphs_enter_stop()

ra8_err_t ra8_acmphs_enter_stop ( uint8_t channel)
nodiscard

Put one channel into MSTP-gated stop.

Since
0.1.0

Definition at line 262 of file ra8_acmphs.c.

References k_ra8_acmphs_channel_count, k_ra8_acmphs_mstp_id_count, k_ra8_err_invalid_arg, k_ra8_ok, ra8_mstp_disable(), and s_acmphs_mstp_table.

◆ ra8_acmphs_exit_stop()

ra8_err_t ra8_acmphs_exit_stop ( uint8_t channel)
nodiscard

Exit MSTP-gated stop for one channel.

Since
0.1.0

Definition at line 273 of file ra8_acmphs.c.

References k_ra8_acmphs_channel_count, k_ra8_acmphs_mstp_id_count, k_ra8_err_invalid_arg, k_ra8_ok, ra8_mstp_enable(), and s_acmphs_mstp_table.

◆ ra8_acmphs_get_status()

ra8_err_t ra8_acmphs_get_status ( uint8_t channel,
uint8_t * out_mask )
nodiscard

Read CMPCTL enable / edge bits.

Parameters
[in]channelChannel 0..5.
[out]out_maskCMPCTL value.
Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 230 of file ra8_acmphs.c.

References r_acmphs_regs_t::CMPCTL, k_ra8_acmphs_channel_count, k_ra8_acmphs_ctl_mask, k_ra8_err_invalid_arg, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, and s_tag.

◆ ra8_acmphs_init()

ra8_err_t ra8_acmphs_init ( void )
nodiscard

Legacy init – reset every channel to its power-on state.

Returns
k_ra8_ok on success.
Since
0.1.0

Definition at line 101 of file ra8_acmphs.c.

References internal_reset_channel(), k_ra8_acmphs_channel_count, k_ra8_ok, ra8_log_info, RA8_RETURN_ON_ERROR, and s_tag.

Referenced by internal_acmphs_demo_setup(), and ra8_nsc_acmphs_init().

◆ ra8_acmphs_read_output()

ra8_err_t ra8_acmphs_read_output ( uint8_t channel,
ra8_level_t * out )
nodiscard

Read the live output of a channel.

Parameters
[in]channelChannel index (0..5).
[out]outReceives k_ra8_level_high or k_ra8_level_low.
Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 127 of file ra8_acmphs.c.

References r_acmphs_regs_t::CMPMON, k_ra8_acmphs_channel_count, k_ra8_acmphs_mask_hcmon, k_ra8_err_invalid_arg, k_ra8_level_high, k_ra8_level_low, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, and s_tag.

Referenced by internal_acmphs_demo_one_iter(), and ra8_nsc_acmphs_read_output().

◆ ra8_acmphs_set_inputs()

ra8_err_t ra8_acmphs_set_inputs ( uint8_t channel,
uint8_t ivpsel,
uint8_t ivrefsel )
nodiscard

Change the input selection of one channel at runtime.

Parameters
[in]channelChannel 0..5.
[in]ivpselPlus-input selector.
[in]ivrefselMinus-input selector.
Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 217 of file ra8_acmphs.c.

References r_acmphs_regs_t::CMPSEL0, r_acmphs_regs_t::CMPSEL1, k_ra8_acmphs_channel_count, k_ra8_err_invalid_arg, k_ra8_ok, ra8_acmphs(), RA8_CHECK_NULL_PTR, and s_tag.