|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Multi-function Pin Controller facade implementation. More...
#include "ra8_mpc.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_log.h"#include "ra8_pfs_regs.h"Go to the source code of this file.
Functions | |
| static ra8_err_t | internal_check (ra8_port_t port, ra8_pin_t pin) |
| Bounds-check a (port, pin) pair. | |
| static void | internal_update_pfs (ra8_port_t port, ra8_pin_t pin, uint32_t clear_mask, uint32_t set_mask) |
| Update a single field of PmnPFS under PWPR unlock. | |
| static void | internal_reset_pfs (ra8_port_t port, ra8_pin_t pin, uint32_t set_mask) |
| All-fields reset + new-fields write under PWPR unlock. | |
| ra8_err_t | ra8_mpc_route_peripheral (ra8_port_t port, ra8_pin_t pin, ra8_mpc_psel_t psel) |
| Route a pin to a peripheral function. | |
| ra8_err_t | ra8_mpc_set_gpio (ra8_port_t port, ra8_pin_t pin, ra8_mpc_dir_t dir) |
| Reset a pin to plain GPIO with a chosen direction. | |
| ra8_err_t | ra8_mpc_set_analog (ra8_port_t port, ra8_pin_t pin) |
| Put a pin in analog-input mode (ASEL = 1). | |
| ra8_err_t | ra8_mpc_set_irq (ra8_port_t port, ra8_pin_t pin) |
| Mark a pin as an external IRQ input (ISEL = 1). | |
| ra8_err_t | ra8_mpc_set_pull (ra8_port_t port, ra8_pin_t pin, ra8_mpc_pull_t pull) |
| Enable or disable the internal pull-up on a pin. | |
| ra8_err_t | ra8_mpc_set_open_drain (ra8_port_t port, ra8_pin_t pin, bool enable) |
| Enable or disable N-channel open-drain on a pin. | |
| ra8_err_t | ra8_mpc_read_pfs (ra8_port_t port, ra8_pin_t pin, uint32_t *out_val) |
| Read the raw 32-bit PmnPFS register for diagnostic use. | |
Variables | |
| static const char * | s_tag = "MPC" |
Multi-function Pin Controller facade implementation.
Ring 3 / HAL substrate. Owns every write to PmnPFS and the accompanying PWPR unlock/lock sequence. See ra8_mpc.h for the API contract.
Definition in file ra8_mpc.c.
|
static |
Bounds-check a (port, pin) pair.
See implementation.
| [in] | port | See implementation. |
| [in] | pin | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 46 of file ra8_mpc.c.
References k_ra8_err_gpio_invalid_pin, k_ra8_err_gpio_invalid_port, k_ra8_ok, k_ra8_pin_max, k_ra8_port_max, pin, and RA8_INTERNAL.
Referenced by ra8_mpc_read_pfs(), ra8_mpc_route_peripheral(), ra8_mpc_set_analog(), ra8_mpc_set_gpio(), ra8_mpc_set_irq(), ra8_mpc_set_open_drain(), and ra8_mpc_set_pull().
|
static |
All-fields reset + new-fields write under PWPR unlock.
Used by the "route" and "set_*" helpers that want to take a pin from whatever state it is in and put it in a clean known state. The register is rewritten from 0 with only the new field bits set; any leftover PSEL / ISEL / ASEL / PDR bits are cleared in the same cycle.
| [in] | port | See implementation. |
| [in] | pin | See implementation. |
| [in] | set_mask | See implementation. |
Definition at line 111 of file ra8_mpc.c.
References pin, RA8_INTERNAL, ra8_pfs_pmn(), ra8_pfs_pwpr_lock(), and ra8_pfs_pwpr_unlock().
Referenced by ra8_mpc_set_analog(), ra8_mpc_set_gpio(), and ra8_mpc_set_irq().
|
static |
Update a single field of PmnPFS under PWPR unlock.
Read-modify-write the whole 32-bit register with the requested field bits cleared and set. PWPR is unlocked once per call and re-locked unconditionally, including on the no-op path.
| [in] | port | See implementation. |
| [in] | pin | See implementation. |
| [in] | clear_mask | See implementation. |
| [in] | set_mask | See implementation. |
Definition at line 77 of file ra8_mpc.c.
References pin, ra8_pfs_pmn(), ra8_pfs_pwpr_lock(), and ra8_pfs_pwpr_unlock().
Referenced by ra8_mpc_set_open_drain(), and ra8_mpc_set_pull().
|
nodiscard |
Read the raw 32-bit PmnPFS register for diagnostic use.
| [in] | port | Port index. |
| [in] | pin | Pin index. |
| [out] | out_val | On success, the current PmnPFS value. |
| k_ra8_ok | Value returned. |
| k_ra8_err_null_ptr | out_val was NULL. |
| k_ra8_err_gpio_invalid_port | Port out of range. |
| k_ra8_err_gpio_invalid_pin | Pin out of range. |
Definition at line 212 of file ra8_mpc.c.
References internal_check(), k_ra8_err_gpio_invalid_pin, k_ra8_ok, pin, RA8_CHECK_NULL_PTR, ra8_pfs_pmn(), and s_tag.
|
nodiscard |
Route a pin to a peripheral function.
Unlocks PWPR, writes the pin's PmnPFS register with PMR = 1 and PSEL = psel, then re-locks PWPR. Any stale direction / pull / open-drain bits are cleared in the same write so the caller sees a clean slate.
| [in] | port | Port index 0..k_ra8_port_max. |
| [in] | pin | Pin index 0..k_ra8_pin_max. |
| [in] | psel | Peripheral function from ra8_mpc_psel_t. |
| k_ra8_ok | Pin routed. |
| k_ra8_err_gpio_invalid_port | port index out of range. |
| k_ra8_err_gpio_invalid_pin | pin index out of range. |
Definition at line 122 of file ra8_mpc.c.
References internal_check(), k_ra8_err_gpio_invalid_pin, k_ra8_ok, k_ra8_pfs_bit_psel0, k_ra8_pfs_mask_pmr, k_ra8_pfs_mask_psel, pin, ra8_log_info_val, ra8_pfs_pmn(), ra8_pfs_pwpr_lock(), ra8_pfs_pwpr_unlock(), and s_tag.
|
nodiscard |
Put a pin in analog-input mode (ASEL = 1).
| [in] | port | Port index. |
| [in] | pin | Pin index. |
| k_ra8_ok | Analog input configured. |
| k_ra8_err_gpio_invalid_port | Port out of range. |
| k_ra8_err_gpio_invalid_pin | Pin out of range. |
Definition at line 167 of file ra8_mpc.c.
References internal_check(), internal_reset_pfs(), k_ra8_ok, k_ra8_pfs_mask_asel, and pin.
|
nodiscard |
Reset a pin to plain GPIO with a chosen direction.
| [in] | port | Port index 0..k_ra8_port_max. |
| [in] | pin | Pin index 0..k_ra8_pin_max. |
| [in] | dir | Input or output. |
| k_ra8_ok | Pin reset to GPIO. |
| k_ra8_err_gpio_invalid_port | Port out of range. |
| k_ra8_err_gpio_invalid_pin | Pin out of range. |
Definition at line 156 of file ra8_mpc.c.
References internal_check(), internal_reset_pfs(), k_ra8_mpc_dir_output, k_ra8_ok, k_ra8_pfs_mask_pdr, and pin.
|
nodiscard |
Mark a pin as an external IRQ input (ISEL = 1).
Does NOT program the ICU IELSR entry – that's ra8_isr's job. This helper just flips the pin's PFS so the edge detector is active.
| [in] | port | Port index. |
| [in] | pin | Pin index. |
| k_ra8_ok | Pin ISEL set. |
| k_ra8_err_gpio_invalid_port | Port out of range. |
| k_ra8_err_gpio_invalid_pin | Pin out of range. |
Definition at line 177 of file ra8_mpc.c.
References internal_check(), internal_reset_pfs(), k_ra8_ok, k_ra8_pfs_mask_isel, and pin.
|
nodiscard |
Enable or disable N-channel open-drain on a pin.
| [in] | port | Port index. |
| [in] | pin | Pin index. |
| [in] | enable | true for open-drain, false for CMOS. |
| k_ra8_ok | NCODR updated. |
| k_ra8_err_gpio_invalid_port | Port out of range. |
| k_ra8_err_gpio_invalid_pin | Pin out of range. |
Definition at line 198 of file ra8_mpc.c.
References internal_check(), internal_update_pfs(), k_ra8_ok, k_ra8_pfs_mask_ncodr, and pin.
Referenced by combo_pfs_or_halt(), i3c_demo_pfs_or_halt(), and internal_io_expander_route_pins().
|
nodiscard |
Enable or disable the internal pull-up on a pin.
| [in] | port | Port index. |
| [in] | pin | Pin index. |
| [in] | pull | Off or on. |
| k_ra8_ok | Pull updated. |
| k_ra8_err_gpio_invalid_port | Port out of range. |
| k_ra8_err_gpio_invalid_pin | Pin out of range. |
Definition at line 187 of file ra8_mpc.c.
References internal_check(), internal_update_pfs(), k_ra8_mpc_pull_up, k_ra8_ok, k_ra8_pfs_mask_pcr, and pin.