跳转至

lib/gpio/gpio.h

GPIO abstraction and helpers used by platform and application code. More...

Classes

Name
struct CFBD_GPIOHandle
Public GPIO handle combining platform handle and pin id.

Types

Name
typedef uint32_t GPIO_PinType
Integral type used to identify a single GPIO pin.
typedef void * GPIO_TypeHandle
Opaque handle type referring to platform-specific GPIO state.
typedef void * CFBD_GPIOInitParams
Opaque pointer type for GPIO initialization parameters.

Functions

Name
void CFBD_GPIOInit(CFBD_GPIOHandle * handle, CFBD_GPIOInitParams params)
Initialize a GPIO handle for subsequent operations.
void CFBD_GPIOSet(CFBD_GPIOHandle * handle)
Set (drive high) the GPIO represented by handle.
void CFBD_GPIOUnset(CFBD_GPIOHandle * handle)
Clear (drive low) the GPIO represented by handle.
void CFBD_GPIOToggle(CFBD_GPIOHandle * handle)
Toggle the GPIO represented by handle.
void CFBD_GPIOSetPin(CFBD_GPIOHandle * handle, CFBD_Bool status)
Inline helper to set or clear a GPIO based on status.
CFBD_Bool CFBD_GPIOReadPin(CFBD_GPIOHandle * handle)

Detailed Description

GPIO abstraction and helpers used by platform and application code.

Note: The header assumes a platform-specific implementation header (e.g. [gpio-stm-impl.h](Files/gpio-stm-impl_8h.md#file-gpio-stm-impl.h)) supplies the necessary low-level definitions used by the functions declared here.

This header provides a minimal, portable GPIO interface used by the CFBD project. It defines lightweight handle types, an initialization parameter opaque type and basic operations for setting, clearing and toggling GPIO lines. The concrete backing implementation is selected by platform macros (for example CFBD_IS_ST includes the STM implementation).

The API is intentionally small to keep portability across targets straightforward; callers should ensure the provided handle is valid and the underlying platform driver has been initialized.

Types Documentation

typedef GPIO_PinType

GPIO_PinType;

Integral type used to identify a single GPIO pin.

The concrete meaning (bit-mask, number, encoded port/pin) depends on the platform implementation header. Use GPIO_PinType when storing or passing pin identifiers to the API.

typedef GPIO_TypeHandle

GPIO_TypeHandle;

Opaque handle type referring to platform-specific GPIO state.

Implementations should cast this pointer to an internal structure defined by the platform backend. The type is intentionally opaque to keep the public API independent from implementation details.

typedef CFBD_GPIOInitParams

CFBD_GPIOInitParams;

Opaque pointer type for GPIO initialization parameters.

Allows platform or application-specific initialization data to be passed to CFBD_GPIOInit. Cast to the concrete type expected by the underlying implementation when processing.

Functions Documentation

function CFBD_GPIOInit

void CFBD_GPIOInit(
    CFBD_GPIOHandle * handle,
    CFBD_GPIOInitParams params
)

Initialize a GPIO handle for subsequent operations.

Parameters:

  • handle Pointer to a [CFBD_GPIOHandle](Classes/structCFBD__GPIOHandle.md) structure to initialize.
  • params Opaque initialization parameters (may be NULL).

Performs any required platform-specific setup of handle using the supplied params. After successful initialization the handle should be ready for CFBD_GPIOSet/CFBD_GPIOUnset/CFBD_GPIOToggle.

function CFBD_GPIOSet

void CFBD_GPIOSet(
    CFBD_GPIOHandle * handle
)

Set (drive high) the GPIO represented by handle.

Parameters:

  • handle Pointer to an initialized [CFBD_GPIOHandle](Classes/structCFBD__GPIOHandle.md).

function CFBD_GPIOUnset

void CFBD_GPIOUnset(
    CFBD_GPIOHandle * handle
)

Clear (drive low) the GPIO represented by handle.

Parameters:

  • handle Pointer to an initialized [CFBD_GPIOHandle](Classes/structCFBD__GPIOHandle.md).

function CFBD_GPIOToggle

void CFBD_GPIOToggle(
    CFBD_GPIOHandle * handle
)

Toggle the GPIO represented by handle.

Parameters:

  • handle Pointer to an initialized [CFBD_GPIOHandle](Classes/structCFBD__GPIOHandle.md).

function CFBD_GPIOSetPin

static inline void CFBD_GPIOSetPin(
    CFBD_GPIOHandle * handle,
    CFBD_Bool status
)

Inline helper to set or clear a GPIO based on status.

Parameters:

  • handle Pointer to an initialized [CFBD_GPIOHandle](Classes/structCFBD__GPIOHandle.md).
  • status If CFBD_TRUE, set the pin; if CFBD_FALSE, clear it.

Convenience wrapper that calls CFBD_GPIOSet when status is true, otherwise calls CFBD_GPIOUnset.

function CFBD_GPIOReadPin

CFBD_Bool CFBD_GPIOReadPin(
    CFBD_GPIOHandle * handle
)

Source code

#pragma once
#include "cfbd_define.h"
#include "lib_settings.h"

#if defined(CFBD_IS_ST)
#include "../gpio/gpio-stm-impl.h"
#else
#error "No supports chips"
#endif

typedef uint32_t GPIO_PinType;

typedef void* GPIO_TypeHandle;

typedef struct
{
    GPIO_TypeHandle handle_internals_;

    GPIO_PinType pin_internals_;
} CFBD_GPIOHandle;

typedef void* CFBD_GPIOInitParams;

void CFBD_GPIOInit(CFBD_GPIOHandle* handle, CFBD_GPIOInitParams params);

void CFBD_GPIOSet(CFBD_GPIOHandle* handle);

void CFBD_GPIOUnset(CFBD_GPIOHandle* handle);

void CFBD_GPIOToggle(CFBD_GPIOHandle* handle);

static void inline CFBD_GPIOSetPin(CFBD_GPIOHandle* handle, CFBD_Bool status)
{
    status ? CFBD_GPIOSet(handle) : CFBD_GPIOUnset(handle);
}

CFBD_Bool CFBD_GPIOReadPin(CFBD_GPIOHandle* handle);

Updated on 2026-02-03 at 13:21:55 +0000