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_dac.h
Go to the documentation of this file.
1
26#ifndef CAFFEINE_HAL_HAL_DAC_H
27#define CAFFEINE_HAL_HAL_DAC_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
53
63
77
85/* Types Structs ----------------------------------------------------*/
86
90typedef struct
91{
92 void *instance;
93 uint32_t channel;
95 void *user_arg;
97
107
108typedef struct cfn_hal_dac_s cfn_hal_dac_t;
110
118typedef void (*cfn_hal_dac_callback_t)(cfn_hal_dac_t *driver, uint32_t event_mask, uint32_t error_mask, void *user_arg);
119
124{
126
127 /* DAC Specific Extensions */
128 cfn_hal_error_code_t (*set_value)(cfn_hal_dac_t *driver, uint32_t value, uint32_t timeout);
131 cfn_hal_error_code_t (*write_dma)(cfn_hal_dac_t *driver, const uint32_t *data, size_t nbr_of_samples);
132};
133
135
137
138/* Functions inline ------------------------------------------------- */
140 uint32_t peripheral_id,
141 struct cfn_hal_clock_s *clock,
142 void *dependency,
143 const cfn_hal_dac_api_t *api,
144 const cfn_hal_dac_phy_t *phy,
145 const cfn_hal_dac_config_t *config,
146 cfn_hal_dac_callback_t callback,
147 void *user_arg)
148{
150 driver, CFN_HAL_PERIPHERAL_TYPE_DAC, peripheral_id, clock, dependency, api, phy, config, callback, user_arg);
151}
152
160 const cfn_hal_dac_config_t *config)
161{
162 if (driver == NULL || config == NULL)
163 {
165 }
166
168 {
170 }
171
172 return cfn_hal_base_config_validate(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DAC, config);
173}
174
181{
182 if (!driver)
183 {
185 }
186 driver->base.vmt = (const struct cfn_hal_api_base_s *) driver->api;
187 cfn_hal_error_code_t error = cfn_hal_dac_config_validate(driver, driver->config);
188 if (error != CFN_HAL_ERROR_OK)
189 {
190 return error;
191 }
192 return cfn_hal_base_init(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DAC);
193}
194
201{
202 if (!driver)
203 {
205 }
207}
208
216{
217 if (!driver)
218 {
220 }
222 if (error != CFN_HAL_ERROR_OK)
223 {
224 return error;
225 }
226 {
227 driver->config = config;
228 }
229 return cfn_hal_base_config_set(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DAC, (const void *) config);
230}
231
239{
240 if (!driver || !config || !driver->config)
241 {
243 }
244 *config = *(driver->config);
245 return CFN_HAL_ERROR_OK;
246}
247
256 const cfn_hal_dac_callback_t callback,
257 void *user_arg)
258{
259 if (!driver)
260 {
262 }
263 {
264 driver->cb = callback;
265 driver->cb_user_arg = user_arg;
266 }
268 &driver->base, CFN_HAL_PERIPHERAL_TYPE_DAC, (cfn_hal_callback_t) callback, user_arg);
269}
270
285
293{
294 if (!driver)
295 {
297 }
298 return cfn_hal_base_event_enable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DAC, event_mask);
299}
300
308{
309 if (!driver)
310 {
312 }
313 return cfn_hal_base_event_disable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DAC, event_mask);
314}
315
323{
324 if (!driver)
325 {
327 }
328 return cfn_hal_base_event_get(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DAC, event_mask);
329}
330
338{
339 if (!driver)
340 {
342 }
343 return cfn_hal_base_error_enable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DAC, error_mask);
344}
345
353{
354 if (!driver)
355 {
357 }
358 return cfn_hal_base_error_disable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DAC, error_mask);
359}
360
368{
369 if (!driver)
370 {
372 }
373 return cfn_hal_base_error_get(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DAC, error_mask);
374}
375
376/* DAC Specific Functions ------------------------------------------- */
377
386{
388 CFN_HAL_CHECK_AND_CALL_FUNC_VARG(CFN_HAL_PERIPHERAL_TYPE_DAC, set_value, driver, error, value, timeout);
389 return error;
390}
391
403
415
424 const uint32_t *data,
425 size_t nbr_of_samples)
426{
428 CFN_HAL_CHECK_AND_CALL_FUNC_VARG(CFN_HAL_PERIPHERAL_TYPE_DAC, write_dma, driver, error, data, nbr_of_samples);
429 return error;
430}
432 const cfn_hal_dac_config_t *config,
433 const cfn_hal_dac_phy_t *phy,
434 struct cfn_hal_clock_s *clock,
435 void *dependency,
436 cfn_hal_dac_callback_t callback,
437 void *user_arg);
439
440#ifdef __cplusplus
441}
442#endif
443
444#endif // CAFFEINE_HAL_HAL_DAC_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_dac_start(cfn_hal_dac_t *driver)
Starts DAC conversion (e.g., enables output).
Definition cfn_hal_dac.h:397
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_stop(cfn_hal_dac_t *driver)
Stops DAC conversion (e.g., disables output).
Definition cfn_hal_dac.h:409
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_config_get(cfn_hal_dac_t *driver, cfn_hal_dac_config_t *config)
Gets the current DAC configuration.
Definition cfn_hal_dac.h:238
cfn_hal_dac_resolution_t
Definition cfn_hal_dac.h:65
@ CFN_HAL_DAC_RESOLUTION_BIT_14
Definition cfn_hal_dac.h:71
@ CFN_HAL_DAC_RESOLUTION_BIT_8
Definition cfn_hal_dac.h:68
@ CFN_HAL_DAC_RESOLUTION_BIT_24
Definition cfn_hal_dac.h:73
@ CFN_HAL_DAC_RESOLUTION_BIT_6
Definition cfn_hal_dac.h:67
@ CFN_HAL_DAC_RESOLUTION_BIT_12
Definition cfn_hal_dac.h:70
@ CFN_HAL_DAC_RESOLUTION_BIT_MAX
Definition cfn_hal_dac.h:75
@ CFN_HAL_DAC_RESOLUTION_BIT_16
Definition cfn_hal_dac.h:72
@ CFN_HAL_DAC_RESOLUTION_BIT_4
Definition cfn_hal_dac.h:66
@ CFN_HAL_DAC_RESOLUTION_BIT_10
Definition cfn_hal_dac.h:69
cfn_hal_dac_event_t
DAC nominal event flags.
Definition cfn_hal_dac.h:48
@ CFN_HAL_DAC_EVENT_DMA_COMPLETE
Definition cfn_hal_dac.h:51
@ CFN_HAL_DAC_EVENT_DMA_HALF
Definition cfn_hal_dac.h:50
@ CFN_HAL_DAC_EVENT_NONE
Definition cfn_hal_dac.h:49
cfn_hal_dac_error_t
DAC exception error flags.
Definition cfn_hal_dac.h:58
@ CFN_HAL_DAC_ERROR_UNDERRUN
Definition cfn_hal_dac.h:60
@ CFN_HAL_DAC_ERROR_NONE
Definition cfn_hal_dac.h:59
@ CFN_HAL_DAC_ERROR_GENERAL
Definition cfn_hal_dac.h:61
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_error_enable(cfn_hal_dac_t *driver, uint32_t error_mask)
Enables one or more DAC exception errors.
Definition cfn_hal_dac.h:337
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_config_set(cfn_hal_dac_t *driver, const cfn_hal_dac_config_t *config)
Sets the DAC configuration.
Definition cfn_hal_dac.h:215
struct cfn_hal_dac_s cfn_hal_dac_t
Definition cfn_hal_dac.h:108
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_error_get(cfn_hal_dac_t *driver, uint32_t *error_mask)
Retrieves the current DAC exception error status.
Definition cfn_hal_dac.h:367
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_init(cfn_hal_dac_t *driver)
Initializes the DAC driver.
Definition cfn_hal_dac.h:180
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_set_value(cfn_hal_dac_t *driver, uint32_t value, uint32_t timeout)
Sets the analog output value (blocking).
Definition cfn_hal_dac.h:385
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_write_dma(cfn_hal_dac_t *driver, const uint32_t *data, size_t nbr_of_samples)
Starts continuous DAC output using DMA.
Definition cfn_hal_dac.h:423
cfn_hal_error_code_t cfn_hal_dac_construct(cfn_hal_dac_t *driver, const cfn_hal_dac_config_t *config, const cfn_hal_dac_phy_t *phy, struct cfn_hal_clock_s *clock, void *dependency, cfn_hal_dac_callback_t callback, void *user_arg)
Definition cfn_hal_dac_port.c:97
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_error_disable(cfn_hal_dac_t *driver, uint32_t error_mask)
Disables one or more DAC exception errors.
Definition cfn_hal_dac.h:352
cfn_hal_dac_align_t
Definition cfn_hal_dac.h:79
@ CFN_HAL_DAC_ALIGN_MAX
Definition cfn_hal_dac.h:83
@ CFN_HAL_DAC_ALIGN_LEFT
Definition cfn_hal_dac.h:81
@ CFN_HAL_DAC_ALIGN_RIGHT
Definition cfn_hal_dac.h:80
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_power_state_set(cfn_hal_dac_t *driver, cfn_hal_power_state_t state)
Sets the DAC power state.
Definition cfn_hal_dac.h:277
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_deinit(cfn_hal_dac_t *driver)
Deinitializes the DAC driver.
Definition cfn_hal_dac.h:200
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_callback_register(cfn_hal_dac_t *driver, const cfn_hal_dac_callback_t callback, void *user_arg)
Registers a callback for DAC events and errors.
Definition cfn_hal_dac.h:255
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_event_enable(cfn_hal_dac_t *driver, uint32_t event_mask)
Enables one or more DAC nominal events.
Definition cfn_hal_dac.h:292
void(* cfn_hal_dac_callback_t)(cfn_hal_dac_t *driver, uint32_t event_mask, uint32_t error_mask, void *user_arg)
DAC callback signature.
Definition cfn_hal_dac.h:118
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_event_get(cfn_hal_dac_t *driver, uint32_t *event_mask)
Retrieves the current DAC nominal event status.
Definition cfn_hal_dac.h:322
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_config_validate(const cfn_hal_dac_t *driver, const cfn_hal_dac_config_t *config)
Validates the DAC configuration.
Definition cfn_hal_dac.h:159
cfn_hal_error_code_t cfn_hal_dac_destruct(cfn_hal_dac_t *driver)
Definition cfn_hal_dac_port.c:113
CFN_HAL_INLINE void cfn_hal_dac_populate(cfn_hal_dac_t *driver, uint32_t peripheral_id, struct cfn_hal_clock_s *clock, void *dependency, const cfn_hal_dac_api_t *api, const cfn_hal_dac_phy_t *phy, const cfn_hal_dac_config_t *config, cfn_hal_dac_callback_t callback, void *user_arg)
Definition cfn_hal_dac.h:139
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dac_event_disable(cfn_hal_dac_t *driver, uint32_t event_mask)
Disables one or more DAC nominal events.
Definition cfn_hal_dac.h:307
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_DAC
Definition cfn_hal_types.h:123
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
DAC Virtual Method Table (VMT).
Definition cfn_hal_dac.h:124
cfn_hal_error_code_t(* stop)(cfn_hal_dac_t *driver)
Definition cfn_hal_dac.h:130
cfn_hal_error_code_t(* start)(cfn_hal_dac_t *driver)
Definition cfn_hal_dac.h:129
cfn_hal_api_base_t base
Definition cfn_hal_dac.h:125
cfn_hal_error_code_t(* write_dma)(cfn_hal_dac_t *driver, const uint32_t *data, size_t nbr_of_samples)
Definition cfn_hal_dac.h:131
cfn_hal_error_code_t(* set_value)(cfn_hal_dac_t *driver, uint32_t value, uint32_t timeout)
Definition cfn_hal_dac.h:128
DAC configuration structure.
Definition cfn_hal_dac.h:102
void * custom
Definition cfn_hal_dac.h:105
cfn_hal_dac_resolution_t resolution
Definition cfn_hal_dac.h:104
cfn_hal_dac_align_t alignment
Definition cfn_hal_dac.h:103
DAC hardware physical mapping.
Definition cfn_hal_dac.h:91
uint32_t channel
Definition cfn_hal_dac.h:93
void * instance
Definition cfn_hal_dac.h:92
void * user_arg
Definition cfn_hal_dac.h:95
cfn_hal_gpio_pin_handle_t * pin
Definition cfn_hal_dac.h:94
Lightweight handle to a specific GPIO pin. Used by other peripherals to reference physical pins.
Definition cfn_hal_gpio.h:173