caffeine-hal 0.6.6
A Header-Defined Interface c library, it provides the hal layer for the Caffeine framework
Loading...
Searching...
No Matches
cfn_hal_comp.h
Go to the documentation of this file.
1
26#ifndef CAFFEINE_HAL_HAL_COMP_H
27#define CAFFEINE_HAL_HAL_COMP_H
28
29#ifdef __cplusplus
30extern "C"
31{
32#endif
33
34/* Includes ---------------------------------------------------------*/
35#include "cfn_hal.h"
36#include "cfn_hal_base.h"
37#include "cfn_hal_gpio.h"
38#include "cfn_hal_types.h"
39
40/* Defines ----------------------------------------------------------*/
41
42/* Types Enums ------------------------------------------------------*/
43
52
61
70
71/* Types Structs ----------------------------------------------------*/
72
84
88typedef struct
89{
92
93typedef struct cfn_hal_comp_s cfn_hal_comp_t;
95
104 uint32_t event_mask,
105 uint32_t error_mask,
106 void *user_arg);
107
121
123
126
127/* Functions inline ------------------------------------------------- */
129 uint32_t peripheral_id,
130 struct cfn_hal_clock_s *clock,
131 void *dependency,
132 const cfn_hal_comp_api_t *api,
133 const cfn_hal_comp_phy_t *phy,
134 const cfn_hal_comp_config_t *config,
136 void *user_arg)
137{
139 driver, CFN_HAL_PERIPHERAL_TYPE_COMP, peripheral_id, clock, dependency, api, phy, config, callback, user_arg);
140}
141
149 const cfn_hal_comp_config_t *config)
150{
151 if (driver == NULL || config == NULL)
152 {
154 }
155
156 return cfn_hal_base_config_validate(&driver->base, CFN_HAL_PERIPHERAL_TYPE_COMP, config);
157}
158
165{
166 if (!driver)
167 {
169 }
170 driver->base.vmt = (const struct cfn_hal_api_base_s *) driver->api;
171 cfn_hal_error_code_t error = cfn_hal_comp_config_validate(driver, driver->config);
172 if (error != CFN_HAL_ERROR_OK)
173 {
174 return error;
175 }
176 return cfn_hal_base_init(&driver->base, CFN_HAL_PERIPHERAL_TYPE_COMP);
177}
178
185{
186 if (!driver)
187 {
189 }
191}
192
200{
201 if (!driver)
202 {
204 }
206 if (error != CFN_HAL_ERROR_OK)
207 {
208 return error;
209 }
210 {
211 driver->config = config;
212 }
213 return cfn_hal_base_config_set(&driver->base, CFN_HAL_PERIPHERAL_TYPE_COMP, (const void *) config);
214}
215
223{
224 if (!driver || !config || !driver->config)
225 {
227 }
228 *config = *(driver->config);
229 return CFN_HAL_ERROR_OK;
230}
231
240 const cfn_hal_comp_callback_t callback,
241 void *user_arg)
242{
243 if (!driver)
244 {
246 }
247 {
248 driver->cb = callback;
249 driver->cb_user_arg = user_arg;
250 }
252 &driver->base, CFN_HAL_PERIPHERAL_TYPE_COMP, (cfn_hal_callback_t) callback, user_arg);
253}
254
269
277{
278 if (!driver)
279 {
281 }
282 return cfn_hal_base_event_enable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_COMP, event_mask);
283}
284
292{
293 if (!driver)
294 {
296 }
297 return cfn_hal_base_event_disable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_COMP, event_mask);
298}
299
307{
308 if (!driver)
309 {
311 }
312 return cfn_hal_base_event_get(&driver->base, CFN_HAL_PERIPHERAL_TYPE_COMP, event_mask);
313}
314
322{
323 if (!driver)
324 {
326 }
327 return cfn_hal_base_error_enable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_COMP, error_mask);
328}
329
337{
338 if (!driver)
339 {
341 }
342 return cfn_hal_base_error_disable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_COMP, error_mask);
343}
344
352{
353 if (!driver)
354 {
356 }
357 return cfn_hal_base_error_get(&driver->base, CFN_HAL_PERIPHERAL_TYPE_COMP, error_mask);
358}
359
360/* COMP Specific Functions ------------------------------------------ */
361
374
383{
385 CFN_HAL_CHECK_AND_CALL_FUNC_VARG(CFN_HAL_PERIPHERAL_TYPE_COMP, set_threshold, driver, error, threshold);
386 return error;
387}
388
400
412
414 const cfn_hal_comp_config_t *config,
415 const cfn_hal_comp_phy_t *phy,
416 struct cfn_hal_clock_s *clock,
417 void *dependency,
419 void *user_arg);
421#ifdef __cplusplus
422}
423#endif
424
425#endif // CAFFEINE_HAL_HAL_COMP_H
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_CHECK_AND_CALL_FUNC(expected_peripheral_type, func, driver, result)
Definition cfn_hal.h:114
#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_base_config_set(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, const void *config)
Generic configuration setter for any driver.
Definition cfn_hal_base_impl.h:196
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
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_config_validate(const cfn_hal_comp_t *driver, const cfn_hal_comp_config_t *config)
Validates the Comparator configuration.
Definition cfn_hal_comp.h:148
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_event_get(cfn_hal_comp_t *driver, uint32_t *event_mask)
Retrieves the current Comparator nominal event status.
Definition cfn_hal_comp.h:306
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_power_state_set(cfn_hal_comp_t *driver, cfn_hal_power_state_t state)
Sets the Comparator power state.
Definition cfn_hal_comp.h:261
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_set_threshold(cfn_hal_comp_t *driver, uint32_t threshold)
Dynamically adjusts the reference threshold (if supported by hardware).
Definition cfn_hal_comp.h:382
void(* cfn_hal_comp_callback_t)(cfn_hal_comp_t *driver, uint32_t event_mask, uint32_t error_mask, void *user_arg)
COMP callback signature.
Definition cfn_hal_comp.h:103
cfn_hal_comp_level_t
COMP output levels.
Definition cfn_hal_comp.h:66
@ CFN_HAL_COMP_LEVEL_HIGH
Definition cfn_hal_comp.h:68
@ CFN_HAL_COMP_LEVEL_LOW
Definition cfn_hal_comp.h:67
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_error_disable(cfn_hal_comp_t *driver, uint32_t error_mask)
Disables one or more Comparator exception errors.
Definition cfn_hal_comp.h:336
cfn_hal_comp_event_t
COMP nominal event flags.
Definition cfn_hal_comp.h:48
@ CFN_HAL_COMP_EVENT_TRIGGER
Definition cfn_hal_comp.h:50
@ CFN_HAL_COMP_EVENT_NONE
Definition cfn_hal_comp.h:49
cfn_hal_comp_error_t
COMP exception error flags.
Definition cfn_hal_comp.h:57
@ CFN_HAL_COMP_ERROR_NONE
Definition cfn_hal_comp.h:58
@ CFN_HAL_COMP_ERROR_GENERAL
Definition cfn_hal_comp.h:59
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_config_set(cfn_hal_comp_t *driver, const cfn_hal_comp_config_t *config)
Sets the Comparator configuration.
Definition cfn_hal_comp.h:199
struct cfn_hal_comp_s cfn_hal_comp_t
Definition cfn_hal_comp.h:93
cfn_hal_error_code_t cfn_hal_comp_destruct(cfn_hal_comp_t *driver)
Definition cfn_hal_comp_port.c:85
CFN_HAL_INLINE void cfn_hal_comp_populate(cfn_hal_comp_t *driver, uint32_t peripheral_id, struct cfn_hal_clock_s *clock, void *dependency, const cfn_hal_comp_api_t *api, const cfn_hal_comp_phy_t *phy, const cfn_hal_comp_config_t *config, cfn_hal_comp_callback_t callback, void *user_arg)
Definition cfn_hal_comp.h:128
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_event_disable(cfn_hal_comp_t *driver, uint32_t event_mask)
Disables one or more Comparator nominal events.
Definition cfn_hal_comp.h:291
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_deinit(cfn_hal_comp_t *driver)
Deinitializes the Comparator driver.
Definition cfn_hal_comp.h:184
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_stop(cfn_hal_comp_t *driver)
Disables/Stops the comparator operation.
Definition cfn_hal_comp.h:406
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_error_enable(cfn_hal_comp_t *driver, uint32_t error_mask)
Enables one or more Comparator exception errors.
Definition cfn_hal_comp.h:321
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_init(cfn_hal_comp_t *driver)
Initializes the Comparator driver.
Definition cfn_hal_comp.h:164
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_event_enable(cfn_hal_comp_t *driver, uint32_t event_mask)
Enables one or more Comparator nominal events.
Definition cfn_hal_comp.h:276
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_start(cfn_hal_comp_t *driver)
Enables/Starts the comparator operation.
Definition cfn_hal_comp.h:394
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_read_output(cfn_hal_comp_t *driver, cfn_hal_comp_level_t *level)
Reads the immediate logical output of the comparator.
Definition cfn_hal_comp.h:368
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_callback_register(cfn_hal_comp_t *driver, const cfn_hal_comp_callback_t callback, void *user_arg)
Registers a callback for Comparator events and errors.
Definition cfn_hal_comp.h:239
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_config_get(cfn_hal_comp_t *driver, cfn_hal_comp_config_t *config)
Gets the current Comparator configuration.
Definition cfn_hal_comp.h:222
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_comp_error_get(cfn_hal_comp_t *driver, uint32_t *error_mask)
Retrieves the current Comparator exception error status.
Definition cfn_hal_comp.h:351
cfn_hal_error_code_t cfn_hal_comp_construct(cfn_hal_comp_t *driver, const cfn_hal_comp_config_t *config, const cfn_hal_comp_phy_t *phy, struct cfn_hal_clock_s *clock, void *dependency, cfn_hal_comp_callback_t callback, void *user_arg)
Definition cfn_hal_comp_port.c:69
General Purpose Input/Output (GPIO) HAL API.
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_COMP
Definition cfn_hal_types.h:141
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
Base API structure for all peripheral drivers. Every peripheral-specific API struct MUST have this as...
Definition cfn_hal_base.h:63
COMP Virtual Method Table (VMT).
Definition cfn_hal_comp.h:112
cfn_hal_api_base_t base
Definition cfn_hal_comp.h:113
cfn_hal_error_code_t(* set_threshold)(cfn_hal_comp_t *driver, uint32_t threshold)
Definition cfn_hal_comp.h:117
cfn_hal_error_code_t(* read_output)(cfn_hal_comp_t *driver, cfn_hal_comp_level_t *level)
Definition cfn_hal_comp.h:116
cfn_hal_error_code_t(* stop)(cfn_hal_comp_t *driver)
Definition cfn_hal_comp.h:119
cfn_hal_error_code_t(* start)(cfn_hal_comp_t *driver)
Definition cfn_hal_comp.h:118
COMP configuration structure.
Definition cfn_hal_comp.h:89
void * user_config
Definition cfn_hal_comp.h:90
COMP hardware physical mapping.
Definition cfn_hal_comp.h:77
cfn_hal_gpio_pin_handle_t * output
Definition cfn_hal_comp.h:81
cfn_hal_gpio_pin_handle_t * input_plus
Definition cfn_hal_comp.h:79
cfn_hal_gpio_pin_handle_t * input_minus
Definition cfn_hal_comp.h:80
void * user_arg
Definition cfn_hal_comp.h:82
void * instance
Definition cfn_hal_comp.h:78
Lightweight handle to a specific GPIO pin. Used by other peripherals to reference physical pins.
Definition cfn_hal_gpio.h:173