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

Abstract pin-driver interface for dependency injection. More...

#include "ra8_err.h"
#include "ra8_port_constants.h"
Include dependency graph for ra8_pin_interface.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ra8_pin_interface_t
 Vtable for a pin driver. More...

Detailed Description

Abstract pin-driver interface for dependency injection.

Drivers that need to toggle a GPIO pin (LED blinkers, motor enables, nFAULT inputs, chip-select lines) should not call ra8_gpio_* directly in production code – that couples them to the real hardware and prevents unit testing. Instead they take an ra8_pin_interface_t pointer:

typedef struct {
const ra8_pin_interface_t* pin_if;
ra8_port_pin_t led_pin;
bool initialized;
} led_driver_t;
ra8_err_t led_driver_blink(led_driver_t* drv) {
return drv->pin_if->write(drv->pin_if->ctx, drv->led_pin,
}
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
ra8_port_pin_t
Packed (port << 8) | pin pin identifier.
@ k_ra8_level_high
Drive or read 1.
Vtable for a pin driver.

In production pin_if points at g_ra8_gpio_pin_interface (defined in libs/ra8_hal/src/gpio.c). In tests it points at a mock that records every call.

This is the "Dependency Inversion" D of SOLID. NASA Power of 10 Rule 9 nominally bans function pointers, but this project makes the DI exception called out in CLAUDE.md.

Definition in file ra8_pin_interface.h.