26#ifndef CAFFEINE_HAL_HAL_GPIO_H
27#define CAFFEINE_HAL_HAL_GPIO_H
112#define CFN_HAL_GPIO_PIN_0 CFN_HAL_BIT(0)
113#define CFN_HAL_GPIO_PIN_1 CFN_HAL_BIT(1)
114#define CFN_HAL_GPIO_PIN_2 CFN_HAL_BIT(2)
115#define CFN_HAL_GPIO_PIN_3 CFN_HAL_BIT(3)
116#define CFN_HAL_GPIO_PIN_4 CFN_HAL_BIT(4)
117#define CFN_HAL_GPIO_PIN_5 CFN_HAL_BIT(5)
118#define CFN_HAL_GPIO_PIN_6 CFN_HAL_BIT(6)
119#define CFN_HAL_GPIO_PIN_7 CFN_HAL_BIT(7)
120#define CFN_HAL_GPIO_PIN_8 CFN_HAL_BIT(8)
121#define CFN_HAL_GPIO_PIN_9 CFN_HAL_BIT(9)
122#define CFN_HAL_GPIO_PIN_10 CFN_HAL_BIT(10)
123#define CFN_HAL_GPIO_PIN_11 CFN_HAL_BIT(11)
124#define CFN_HAL_GPIO_PIN_12 CFN_HAL_BIT(12)
125#define CFN_HAL_GPIO_PIN_13 CFN_HAL_BIT(13)
126#define CFN_HAL_GPIO_PIN_14 CFN_HAL_BIT(14)
127#define CFN_HAL_GPIO_PIN_15 CFN_HAL_BIT(15)
128#define CFN_HAL_GPIO_PIN_16 CFN_HAL_BIT(16)
129#define CFN_HAL_GPIO_PIN_17 CFN_HAL_BIT(17)
130#define CFN_HAL_GPIO_PIN_18 CFN_HAL_BIT(18)
131#define CFN_HAL_GPIO_PIN_19 CFN_HAL_BIT(19)
132#define CFN_HAL_GPIO_PIN_20 CFN_HAL_BIT(20)
133#define CFN_HAL_GPIO_PIN_21 CFN_HAL_BIT(21)
134#define CFN_HAL_GPIO_PIN_22 CFN_HAL_BIT(22)
135#define CFN_HAL_GPIO_PIN_23 CFN_HAL_BIT(23)
136#define CFN_HAL_GPIO_PIN_24 CFN_HAL_BIT(24)
137#define CFN_HAL_GPIO_PIN_25 CFN_HAL_BIT(25)
138#define CFN_HAL_GPIO_PIN_26 CFN_HAL_BIT(26)
139#define CFN_HAL_GPIO_PIN_27 CFN_HAL_BIT(27)
140#define CFN_HAL_GPIO_PIN_28 CFN_HAL_BIT(28)
141#define CFN_HAL_GPIO_PIN_29 CFN_HAL_BIT(29)
142#define CFN_HAL_GPIO_PIN_30 CFN_HAL_BIT(30)
143#define CFN_HAL_GPIO_PIN_31 CFN_HAL_BIT(31)
213 uint32_t peripheral_id,
214 struct cfn_hal_clock_s *clock,
234 if (driver == NULL || pin_cfg == NULL)
294 driver->cb = callback;
295 driver->cb_user_arg = user_arg;
499 struct cfn_hal_clock_s *clock,
Core Hardware Abstraction Layer definitions and macros.
#define CFN_HAL_CHECK_AND_CALL_FUNC_VARG(expected_peripheral_type, func, driver, result,...)
Definition cfn_hal.h:134
#define CFN_HAL_INLINE
Macro for inlining HAL wrapper functions. Can be overridden with attribute((always_inline)) for perfo...
Definition cfn_hal.h:61
#define CFN_HAL_BIT(x)
Definition cfn_hal.h:79
#define CFN_HAL_CREATE_DRIVER_TYPE(prefix, config_type, api_type, phy_type, cb_type)
Definition cfn_hal.h:102
Base driver Hardware Abstraction Layer declarations.
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_error_disable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t error_mask)
Generic error disable for any driver. Deactivates exception-flow hardware triggers based on the provi...
Definition cfn_hal_base_impl.h:436
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_callback_register(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, cfn_hal_callback_t callback, void *user_arg)
Generic callback registration for any driver.
Definition cfn_hal_base_impl.h:254
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_error_enable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t error_mask)
Generic error enable for any driver. Activates exception-flow hardware triggers based on the provided...
Definition cfn_hal_base_impl.h:411
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_event_enable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t event_mask)
Generic event enable for any driver. Activates nominal hardware triggers based on the provided mask.
Definition cfn_hal_base_impl.h:331
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_event_get(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t *event_mask)
Generic event status getter for any driver. Retrieves the current nominal hardware triggers/flags.
Definition cfn_hal_base_impl.h:386
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_error_get(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t *error_mask)
Generic error status getter for any driver. Retrieves current exception-flow hardware flags/errors.
Definition cfn_hal_base_impl.h:461
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_power_state_set(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, cfn_hal_power_state_t state)
Generic power state transition for any driver.
Definition cfn_hal_base_impl.h:279
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_deinit(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type)
Generic deinitialization for any driver. Returns the driver to the CONSTRUCTED state and releases boa...
Definition cfn_hal_base_impl.h:144
#define CFN_HAL_VMT_CHECK(api_struct_type)
Compile-time check to ensure a peripheral API struct is compatible with the base layer....
Definition cfn_hal_base.h:91
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_init(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type)
Generic initialization for any driver. Handles board-level hooks, type validation,...
Definition cfn_hal_base_impl.h:85
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_config_validate(const cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, const void *config)
Generic validation for a configuration.
Definition cfn_hal_base_impl.h:234
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_event_disable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t event_mask)
Generic event disable for any driver. Deactivates nominal hardware triggers based on the provided mas...
Definition cfn_hal_base_impl.h:361
#define CFN_HAL_POPULATE_DRIVER( driver_ptr, periph_type, periph_id, clock_ptr, dep_ptr, api_ptr, phy_ptr, cfg_ptr, cb_func, cb_arg)
Standardizes the population of a peripheral driver structure. This macro ensures that the base driver...
Definition cfn_hal_base_impl.h:45
uint32_t cfn_hal_gpio_pin_t
Definition cfn_hal_gpio.h:110
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_port_write(cfn_hal_gpio_t *port, uint32_t pin_mask, uint32_t port_value)
Atomically writes to multiple pins on the port using a mask.
Definition cfn_hal_gpio.h:488
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_pin_config_validate(const cfn_hal_gpio_t *driver, const cfn_hal_gpio_pin_config_t *pin_cfg)
Validates the GPIO pin configuration.
Definition cfn_hal_gpio.h:231
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_pin_read(cfn_hal_gpio_t *port, cfn_hal_gpio_pin_t pin, cfn_hal_gpio_state_t *state)
Reads the logical state of a single GPIO pin.
Definition cfn_hal_gpio.h:430
cfn_hal_gpio_config_speed_t
Definition cfn_hal_gpio.h:92
@ CFN_HAL_GPIO_CONFIG_SPEED_VERY_HIGH
Definition cfn_hal_gpio.h:96
@ CFN_HAL_GPIO_CONFIG_SPEED_MEDIUM
Definition cfn_hal_gpio.h:94
@ CFN_HAL_GPIO_CONFIG_SPEED_HIGH
Definition cfn_hal_gpio.h:95
@ CFN_HAL_GPIO_CONFIG_SPEED_LOW
Definition cfn_hal_gpio.h:93
@ CFN_HAL_GPIO_CONFIG_SPEED_MAX
Definition cfn_hal_gpio.h:98
void(* cfn_hal_gpio_callback_t)(cfn_hal_gpio_t *port, uint32_t event_mask, uint32_t error_mask, void *user_arg)
GPIO callback signature.
Definition cfn_hal_gpio.h:185
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_power_state_set(cfn_hal_gpio_t *driver, cfn_hal_power_state_t state)
Sets the GPIO power state.
Definition cfn_hal_gpio.h:308
cfn_hal_gpio_error_t
GPIO exception error flags.
Definition cfn_hal_gpio.h:57
@ CFN_HAL_GPIO_ERROR_GENERAL
Definition cfn_hal_gpio.h:59
@ CFN_HAL_GPIO_ERROR_NONE
Definition cfn_hal_gpio.h:58
cfn_hal_gpio_config_strength_t
Definition cfn_hal_gpio.h:102
@ CFN_HAL_GPIO_CONFIG_STRENGTH_MAX
Definition cfn_hal_gpio.h:107
@ CFN_HAL_GPIO_CONFIG_STRENGTH_HIGH
Definition cfn_hal_gpio.h:105
@ CFN_HAL_GPIO_CONFIG_STRENGTH_LOW
Definition cfn_hal_gpio.h:103
@ CFN_HAL_GPIO_CONFIG_STRENGTH_MEDIUM
Definition cfn_hal_gpio.h:104
cfn_hal_error_code_t cfn_hal_gpio_construct(cfn_hal_gpio_t *driver, const cfn_hal_gpio_phy_t *phy, struct cfn_hal_clock_s *clock, void *dependency, cfn_hal_gpio_callback_t callback, void *user_arg)
Definition cfn_hal_gpio_port.c:71
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_pin_toggle(cfn_hal_gpio_t *port, cfn_hal_gpio_pin_t pin)
Toggles the logical state of a single GPIO pin.
Definition cfn_hal_gpio.h:461
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_pin_write(cfn_hal_gpio_t *port, cfn_hal_gpio_pin_t pin, cfn_hal_gpio_state_t state)
Writes a logical state to a single GPIO pin.
Definition cfn_hal_gpio.h:446
cfn_hal_gpio_config_pull_t
Definition cfn_hal_gpio.h:83
@ CFN_HAL_GPIO_CONFIG_PULL_NOPULL
Definition cfn_hal_gpio.h:84
@ CFN_HAL_GPIO_CONFIG_PULL_MAX
Definition cfn_hal_gpio.h:88
@ CFN_HAL_GPIO_CONFIG_PULL_PULLUP
Definition cfn_hal_gpio.h:85
@ CFN_HAL_GPIO_CONFIG_PULL_PULLDOWN
Definition cfn_hal_gpio.h:86
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_event_disable(cfn_hal_gpio_t *driver, uint32_t event_mask)
Disables one or more GPIO nominal events.
Definition cfn_hal_gpio.h:338
cfn_hal_gpio_event_t
GPIO nominal event flags.
Definition cfn_hal_gpio.h:47
@ CFN_HAL_GPIO_EVENT_NONE
Definition cfn_hal_gpio.h:48
@ CFN_HAL_GPIO_EVENT_RISING
Definition cfn_hal_gpio.h:49
@ CFN_HAL_GPIO_EVENT_FALLING
Definition cfn_hal_gpio.h:50
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_pin_config(cfn_hal_gpio_t *port, const cfn_hal_gpio_pin_config_t *pin_cfg)
Configures specific pins on the port using a payload structure.
Definition cfn_hal_gpio.h:415
CFN_HAL_INLINE void cfn_hal_gpio_populate(cfn_hal_gpio_t *driver, uint32_t peripheral_id, struct cfn_hal_clock_s *clock, void *dependency, const cfn_hal_gpio_api_t *api, const cfn_hal_gpio_phy_t *phy, cfn_hal_gpio_callback_t callback, void *user_arg)
Definition cfn_hal_gpio.h:212
cfn_hal_gpio_state_t
Definition cfn_hal_gpio.h:63
@ CFN_HAL_GPIO_STATE_LOW
Definition cfn_hal_gpio.h:64
@ CFN_HAL_GPIO_STATE_HIGH
Definition cfn_hal_gpio.h:65
@ CFN_HAL_GPIO_STATE_MAX
Definition cfn_hal_gpio.h:67
cfn_hal_gpio_config_mode_t
Definition cfn_hal_gpio.h:71
@ CFN_HAL_GPIO_CONFIG_MODE_OUTPUT_OD
Definition cfn_hal_gpio.h:75
@ CFN_HAL_GPIO_CONFIG_MODE_OUTPUT_PP
Definition cfn_hal_gpio.h:74
@ CFN_HAL_GPIO_CONFIG_MODE_MAX
Definition cfn_hal_gpio.h:79
@ CFN_HAL_GPIO_CONFIG_MODE_ANALOG
Definition cfn_hal_gpio.h:72
@ CFN_HAL_GPIO_CONFIG_MODE_INPUT
Definition cfn_hal_gpio.h:73
@ CFN_HAL_GPIO_CONFIG_MODE_ALTERNATE_PP
Definition cfn_hal_gpio.h:76
@ CFN_HAL_GPIO_CONFIG_MODE_ALTERNATE_OD
Definition cfn_hal_gpio.h:77
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_event_enable(cfn_hal_gpio_t *driver, uint32_t event_mask)
Enables one or more GPIO nominal events.
Definition cfn_hal_gpio.h:323
struct cfn_hal_gpio_s cfn_hal_gpio_t
Definition cfn_hal_gpio.h:165
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_error_get(cfn_hal_gpio_t *driver, uint32_t *error_mask)
Retrieves the current GPIO exception error status.
Definition cfn_hal_gpio.h:398
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_init(cfn_hal_gpio_t *driver)
Initializes the GPIO driver.
Definition cfn_hal_gpio.h:254
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_port_read(cfn_hal_gpio_t *port, uint32_t *port_value)
Reads the 32-bit raw value of the entire GPIO port.
Definition cfn_hal_gpio.h:474
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_error_disable(cfn_hal_gpio_t *driver, uint32_t error_mask)
Disables one or more GPIO exception errors.
Definition cfn_hal_gpio.h:383
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_deinit(cfn_hal_gpio_t *driver)
Deinitializes the GPIO driver.
Definition cfn_hal_gpio.h:269
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_callback_register(cfn_hal_gpio_t *driver, const cfn_hal_gpio_callback_t callback, void *user_arg)
Registers a callback for GPIO events and errors.
Definition cfn_hal_gpio.h:285
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_event_get(cfn_hal_gpio_t *driver, uint32_t *event_mask)
Retrieves the current GPIO nominal event status.
Definition cfn_hal_gpio.h:353
cfn_hal_error_code_t cfn_hal_gpio_destruct(cfn_hal_gpio_t *driver)
Definition cfn_hal_gpio_port.c:86
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_gpio_error_enable(cfn_hal_gpio_t *driver, uint32_t error_mask)
Enables one or more GPIO exception errors.
Definition cfn_hal_gpio.h:368
Common type definitions and enums for the HAL.
void(* cfn_hal_callback_t)(void)
Generic function pointer for HAL callbacks. Used as a standard-compliant carrier in the base layer.
Definition cfn_hal_types.h:98
enum cfn_hal_error_codes cfn_hal_error_code_t
#define CFN_HAL_PERIPHERAL_TYPE_GPIO
Definition cfn_hal_types.h:125
cfn_hal_power_state_t
Definition cfn_hal_types.h:156
@ CFN_HAL_ERROR_OK
Definition cfn_hal_types.h:50
@ CFN_HAL_ERROR_BAD_PARAM
Definition cfn_hal_types.h:53
@ CFN_HAL_ERROR_BAD_CONFIG
Definition cfn_hal_types.h:60
Base API structure for all peripheral drivers. Every peripheral-specific API struct MUST have this as...
Definition cfn_hal_base.h:63
GPIO Virtual Method Table (VMT).
Definition cfn_hal_gpio.h:191
cfn_hal_api_base_t base
Definition cfn_hal_gpio.h:192
cfn_hal_error_code_t(* pin_read)(cfn_hal_gpio_t *port, cfn_hal_gpio_pin_t pin, cfn_hal_gpio_state_t *state)
Definition cfn_hal_gpio.h:197
cfn_hal_error_code_t(* pin_toggle)(cfn_hal_gpio_t *port, cfn_hal_gpio_pin_t pin)
Definition cfn_hal_gpio.h:199
cfn_hal_error_code_t(* port_write)(cfn_hal_gpio_t *port, uint32_t pin_mask, uint32_t port_value)
Definition cfn_hal_gpio.h:202
cfn_hal_error_code_t(* port_read)(cfn_hal_gpio_t *port, uint32_t *port_value)
Definition cfn_hal_gpio.h:201
cfn_hal_error_code_t(* pin_write)(cfn_hal_gpio_t *port, cfn_hal_gpio_pin_t pin, cfn_hal_gpio_state_t state)
Definition cfn_hal_gpio.h:198
cfn_hal_error_code_t(* pin_config)(cfn_hal_gpio_t *port, const cfn_hal_gpio_pin_config_t *pin_cfg)
Definition cfn_hal_gpio.h:195
Definition cfn_hal_gpio.h:148
void * user_arg
Definition cfn_hal_gpio.h:150
void * port
Definition cfn_hal_gpio.h:149
Definition cfn_hal_gpio.h:154
cfn_hal_gpio_state_t default_state
Definition cfn_hal_gpio.h:160
cfn_hal_gpio_config_strength_t strength
Definition cfn_hal_gpio.h:159
void * custom
Definition cfn_hal_gpio.h:162
cfn_hal_gpio_config_speed_t speed
Definition cfn_hal_gpio.h:158
cfn_hal_gpio_config_pull_t pull
Definition cfn_hal_gpio.h:157
void * alternate
Definition cfn_hal_gpio.h:161
cfn_hal_gpio_pin_t pin_mask
Definition cfn_hal_gpio.h:155
cfn_hal_gpio_config_mode_t mode
Definition cfn_hal_gpio.h:156
Lightweight handle to a specific GPIO pin. Used by other peripherals to reference physical pins.
Definition cfn_hal_gpio.h:173
cfn_hal_gpio_pin_t pin
Definition cfn_hal_gpio.h:175
cfn_hal_gpio_t * port
Definition cfn_hal_gpio.h:174